Excel VBA - workbook add

Rolandos

New Member
Joined
Oct 11, 2018
Messages
7
Good morning Gents.

The following macro attempts to open a new file, take the name of a already opened file and then, save the new file with a variation of the existing file name.
==============================
Private Sub CmdB_Invoice_New_Click()


CurrentfileName = ActiveWorkbook.Name
NewFileName = "DraftInvoice_" & Left(CurrentfileName, Len(CurrentfileName) - 5) & "_" & Format(Now, "yyyy_mm_dd")
'Debug.Print NewFileName


Set newbook = Workbooks.Add
With newbook
.Title = "RGH Invoicing"
SaveTheNewFile = Application.GetSaveAsFilename(InitialFileName:=NewFileName, FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="RGH Save As")
End With


End Sub

========================================
Somehow, Though the save as dialog box is opened with the proper information, after clicking on the "Save" button, nothing happens
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
GetSaveAsFileName displays the standard Save As dialog box and gets a file name from the user without actually saving any files (as explained by Microsoft )
Add a line above End With to save the file something like this (untested)

Code:
If[COLOR=#000000][FONT=Consolas] SaveTheNewFile <>  [/FONT][/COLOR][COLOR=#07704A][FONT=Consolas]False [/FONT][/COLOR][FONT=Consolas]Then[/FONT][COLOR=#000000][FONT=Consolas] .SaveAs(SaveTheNewFile)[/FONT][/COLOR]
 
Last edited:
Upvote 0
:warning: Just spotted I amended the code after you looked at it
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top