VBA Saving new workbook name as String of current open workbook

turbo805

New Member
Joined
Oct 24, 2016
Messages
22
Hello,

Briefly I have a macro that saves my current workbook as two different files--one that is macro enabled and one that isn't.

Runs well.

HOWEVER, I cannot for the life of me get my second file to save based off the name of the first file.

For example, if my first file is saved as "Hippo" I would like the second file to be saved as "HippoVersion2"
The name of my first workbook changes occasionally so I need the second workbooks name to change as well.

So all I'm looking for is a solution to get the string of my work books name correct.
As of now all it does is save my second file as WorkbookName + Version2 (it's not recognizing my saved string value).

Cheers.

Code:
Sub SaveWorkbook()

Dim wb As Workbook, wb2 As Workbook
Dim Path As String
Dim WorkbookName As String
WorkbookName = ActiveWorkbook.Name
Application.DisplayAlerts = False
Path = "C:\Users\" & Environ("Username") & "\Desktop\"
Set wb = ThisWorkbook
wb.SaveCopyAs (Path & "File.xlsm")
Set wb2 = Workbooks.Open(Path & "File.xlsm")
wb2.SaveAs Path & "WorkbookName + Version2.xlsx", xlOpenXMLWorkbook
wb2.Close
Application.DisplayAlerts = True


End Sub
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello,

For example, if my first file is saved as "Hippo" I would like the second file to be saved as "HippoVersion2"
The name of my first workbook changes occasionally so I need the second workbooks name to change as well.

So all I'm looking for is a solution to get the string of my work books name correct.
As of now all it does is save my second file as WorkbookName + Version2 (it's not recognizing my saved string value).

This is untested, but try changing:

Code:
wb2.SaveAs Path & "WorkbookName + Version2.xlsx", xlOpenXMLWorkbook

to this:

Code:
wb2.SaveAs Path & WorkbookName & "Version2.xlsx", xlOpenXMLWorkbook
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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