-
I think this is what you wanted. I've simplified your code in a few areas, especially where the new workbook is opened. Basically a new blank workbook is added and the user can choose their name when they save it.
[vba]
Sub Save_CostSheet()
Dim i As Integer
Dim numberOpenWorkbooks As Integer
Dim choose As String
Dim NewFileName As String
Dim NewTitle As String
Dim SheetName As String
Dim CurrentBook As Workbook
Dim CurrentSheet As Worksheet
Dim NewBook As Workbook
Dim ExistingWB As String
'Name of the cost sheet title.
NewTitle = InputBox("Please Specify the Title for this Cost Sheet", "New Cost Sheet")
If NewTitle = "False" Or NewTitle = "" Then
Exit Sub
End If
'Set the location of the starting point
Set CurrentBook = ActiveWorkbook
Set CurrentSheet = ActiveSheet
'count original number of open workbooks
numberOpenWorkbooks = Application.Workbooks.Count
'work out whether to append to existing Workbook or create new one
repeat_question:
choose = InputBox("Do you want to open an existing Workbook <1> or save to a new Workbook <2>", "Select location for new (copied) sheet")
Select Case Val(choose):
Case 0:
Exit Sub
Case 1:
ExistingWB = Application.GetOpenFilename( _
FileFilter:="Microsoft Excel Workbooks, *.xls; *.xlsx", Title:="Open Workbook")
Workbooks.Open Filename:=ExistingWB
Case 2:
Application.Workbooks.Add
Case Else:
GoTo repeat_question
End Select
'set the newBook as the latest member of the Workbooks collection
Set NewBook = Application.Workbooks(numberOpenWorkbooks + 1)
'Copy the currect sheet before the first sheet of the newly opened or added workbook
CurrentSheet.Copy Before:=NewBook.Sheets(1)
'Set the new Title of the new sheet
NewBook.Sheets(1).Range("A1").Value = NewTitle
End Sub
[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules