Append filename when saving?

john0207

New Member
Joined
Apr 27, 2008
Messages
5
Hi, I have a macro which runs when the workbook is closing where I can create the filename.

Code:
Sub shiftchnage()
'
' shiftchnage Macro
'

FileName1 = InputBox("Input filename ", "Filename")
ActiveWorkbook.Save
 ChDir "c:\"
 ActiveWorkbook.SaveAs Filename:="K:\ESS- 2005\Production Meeting\Daily 6 fundamentals\Current Trackers\UNIT 4 TRACKERS\SCAM Trackers\CAMERA TRACKER\" & FileName1, FileFormat:=52, _
 Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
 CreateBackup:=False
 Call Shell("explorer.exe" & " " & "K:\_Group_Leaders\Group Leader Log\UNIT 1 CHANGEOVERS\", vbNormalFocus)
 
ActiveWorkbook.Save
End Sub

is It possible to change the code in macro so that I can add 4 letters to the existing filename with an input box.?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
cant you add the 4 letters (with the filename) at the : InputBox?
 
Last edited:
Upvote 0
expanding on what was suggested by @ranman256
This would build file name string (incl folder path) as you requested assuming that the workbook is to be saved to the same folder as the original workbook

Code:
Dim x As String, FileName1 As String
With ActiveWorkbook
    x = InputBox("Add 4 letters")
    FileName1 = Left(.FullName, Len(.FullName) - 5) & x
    MsgBox FileName1
End With
 
Last edited:
Upvote 0
And if the workbook is to be saved to a different folder

Code:
FileName1 = DifferentFolderPath & "\" & Left(.Name, Len(.Name) - 5) & x
 
Upvote 0

Forum statistics

Threads
1,215,518
Messages
6,125,292
Members
449,218
Latest member
Excel Master

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