Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Export Specific Sheet in Listbox to New Workbook

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Export Specific Sheet in Listbox to New Workbook

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Workbook to a specific sheet Carlee Excel Programming 2 April 11th 07 08:16 PM
hyperlink to another workbook and a specific sheet Daniel[_21_] Excel Programming 8 October 20th 05 04:57 PM
Open Specific Sheet in Workbook jhahes[_9_] Excel Programming 1 June 24th 05 09:26 PM
Export selected Sheet in a new workbook with old workbook name! gr8guy Excel Programming 5 September 11th 04 01:53 AM
Export just one sheet from a workbook Grek[_3_] Excel Programming 2 May 9th 04 01:52 PM


All times are GMT +1. The time now is 03:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"