View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default get all sheet names in comboBox of activeworkbook and export whenselected

I put a combobox and two commandbuttons on a userform.

This was the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

Dim myVisible As Long
Dim ToWkbk As Workbook
Dim ToWkbkName As String
Dim wksName As String
Dim myWindow As Window

Set myWindow = ActiveWindow

ToWkbkName = "myproject.xls"

If Me.ComboBox1.ListIndex < 0 Then
Beep
Exit Sub 'nothing selected
End If

Set ToWkbk = Nothing
On Error Resume Next
Set ToWkbk = Workbooks(ToWkbkName)
On Error GoTo 0

If ToWkbk Is Nothing Then
MsgBox "Please open: " & ToWkbkName & " first!"
Exit Sub
End If

wksName = Me.ComboBox1.Value

With ActiveWorkbook.Worksheets(wksName)
Application.ScreenUpdating = False
myVisible = .Visible
.Visible = xlSheetVisible
.Copy _
after:=ToWkbk.Sheets(ToWkbk.Sheets.Count)
.Visible = myVisible
myWindow.Activate
Application.ScreenUpdating = True
End With

End Sub
Private Sub UserForm_Initialize()
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
Me.ComboBox1.AddItem wks.Name
Next wks
End Sub


ilyaskazi wrote:

get all sheet names (even hidden or very hidden sheets) in comboBox of
the activeWorkbook upon loading Userform.

If the specific sheet is selected then export that sheets in already
opened workbook(MyProject.xls) when 'cmdImport' button is clicked.

--
ilyaskazi
------------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...o&userid=23969
View this thread: http://www.excelforum.com/showthread...hreadid=378269


--

Dave Peterson