Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
I have a userform with a listbox on it. The list box contains the names of several sheets in my workbook. I would like to enable the user to select a sheet in the list box, and click "Export". On click, i'd like Excel to copy the selected Sheet to a new workbook. The new workbook will be named the same as the sheet selected, and placed on the users Desktop. Can anyone shed some light on this for me? -- Carlee |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Carlee,
'---------------- I have a userform with a listbox on it. The list box contains the names of several sheets in my workbook. I would like to enable the user to select a sheet in the list box, and click "Export". On click, i'd like Excel to copy the selected Sheet to a new workbook. The new workbook will be named the same as the sheet selected, and placed on the users Desktop. Can anyone shed some light on this for me? '--------------- In the Userform module, paste the following code: '============= Private Sub cbExport_Click() '<<==== CHANGE Dim SH As Worksheet Dim WB As Workbook Dim WB2 As Workbook Set WB = ThisWorkbook WB.Sheets(Me.ListBox1.Value).Copy Set WB2 = ActiveWorkbook With WB2 .SaveAs Filename:=WB2.Sheets(1).Name & ".xls" Call SendToDesktop(WB2) .Close End With End Sub '<<============= In a standard module, paste: '============= Sub SendToDesktop(WB As Workbook) Dim oWSH As Object Dim oShortcut As Object Dim myPath As String Dim myShortcutPath As String Dim sStr As String With WB myPath = .FullName sStr = "\" & Left(.Name, Len(.Name) - 4) End With Set oWSH = CreateObject("WScript.Shell") With oWSH myShortcutPath = .SpecialFolders.Item("Desktop") Set oShortcut = .CreateShortcut _ (myShortcutPath & sStr & ".lnk") End With With oShortcut .TargetPath = myPath .Save End With Set oWSH = Nothing End Sub '<<============= --- Regards, Norman |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Opening Workbook to a specific sheet | Excel Programming | |||
hyperlink to another workbook and a specific sheet | Excel Programming | |||
Open Specific Sheet in Workbook | Excel Programming | |||
Export selected Sheet in a new workbook with old workbook name! | Excel Programming | |||
Export just one sheet from a workbook | Excel Programming |