Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saving Selected Worksheets

Good day! I would first like to thank everyone that has posted to this
group as I have learned much by using it.

I would like to create a process that allows the user to select from a
group of cells which contains a list of the worksheets and saves those
worksheets selected (or deletes those not selected). I created the
macro below that works from a command button. Right now I can save all
the worksheets to a new book and name the workbook based on information
provided by the user. However, I can't work out how to remove all the
worksheets that are NOT selected in the list.

For example, say we have on our Cover sheet in cells A20, A21, A22, A23
values 'SheetA', 'DataB', 'MyC',' and 'AnotherD' which correspond to
the names of each sheet in the workbook. The user wants to save 'DataB'
and 'AnotherD' to another workbook, so they select those and click the
macro. I want the cover, 'DataB' and 'AnotherD' saved (or remaining) in
the new workbook.

Below is code I have so far. I haven't been able to come up with how to
procede and code.

Thank you in advance for all you help.


Sub ExporttoNewBook()
On Error GoTo cmdPublish_Click_ERR
Selection.Select
Dim wksht As Worksheet
'SAVE WORKBOOK TO STRING PROVIDED IN COVER SHEET NAMED RANGE
'PublishFile'
Dim PublishFile As String
PublishFile = Range("PublishFile").Value ' PublishFile is obviously a
named range
If Len(PublishFile) < 0 Then
ThisWorkbook.Save
ThisWorkbook.SaveAs PublishFile
'PASTE SPECIAL TO REMOVE FORMULAS
For Each wksht In ThisWorkbook.Worksheets
wksht.Cells.Copy
wksht.Range("A1").PasteSpecial xlPasteValues
Next

'THIS IS WHERE I'M STUCK!!!!!! If there is another way, please adivse
' For Each wksht In ThisWorkbook.Worksheets
' With Selection
' If (wksht.Name = Selection) Then
' wksht.Cells.Copy
' wksht.Range("A1").PasteSpecial xlPasteValues
' End If
' End With
' Next

ThisWorkbook.Save
Else
MsgBox "Please supply a file name to publish as.", vbOKOnly +
vbCritical, "All Stop"
End If

Exit Sub
cmdPublish_Click_ERR:
MsgBox Err.Number & ": " & Err.Description, vbOKOnly + vbCritical,
"All Stop"

End Sub

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
copy only selected worksheets CC Excel Discussion (Misc queries) 1 October 9th 08 06:57 PM
only saving selected cells from a worksheet Robert Loxley Excel Discussion (Misc queries) 0 November 30th 06 02:21 PM
saving combo box selected value MarkDev New Users to Excel 0 June 19th 06 06:45 PM
How do I print out selected worksheets one after the other Greeneyes 22 Excel Worksheet Functions 0 October 26th 05 10:41 AM
Saving selected areas Dave S Excel Discussion (Misc queries) 1 July 21st 05 01:13 PM


All times are GMT +1. The time now is 05:55 AM.

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"