Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save active sheet and one other sheet too 1

Status
Not open for further replies.

coolcarls

Technical User
Jan 19, 2002
182
US
I am using the following code to save the active sheet as a new workbook


ActiveSheet.Copy
ActiveSheet.Name = sht_name
filesavename = Application.GetSaveAsFilename(InitialFileName:=ActiveSheet.Name, _
filefilter:="Excel Workbook (*.xls), *.xls")..............


I need to save one other sheet from the same workbook along with the active sheet.

Thanks

 
It's late and I want to go to the the pub, but this should help:

Code:
Option Explicit

Private Sub Save_two_sheets()
Dim shts As Variant, rtn_shts As String, file_name As String
ask_question:
    rtn_shts = Application.InputBox(Prompt:="Enter the names of the two sheets to copy" _
                                & vbCrLf & "SEPERATED BY ONE COMMA ALONE", Type:=2)
On Error GoTo wrong_entry
shts = Array(Left(rtn_shts, InStr(rtn_shts, ",") - 1), _
                                Right(rtn_shts, Len(rtn_shts) - InStr(rtn_shts, ",")))
Sheets(shts).Copy
file_name = Application.GetSaveAsFilename(InitialFileName:=ActiveSheet.Name, filefilter:="Excel Workbook (*.xls), *.xls")
ActiveWorkbook.SaveAs (file_name)
Exit Sub
wrong_entry:
    MsgBox Prompt:="The sheets you have entered appear to be invalid." & vbCr _
                            & "Please reselect", Buttons:=vbExclamation
    Resume ask_question
End Sub

I don't think there's an easier way round it than to ask which two you want copied.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top