VBA Save file as

Kra

Board Regular
Joined
Jul 4, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi all!

Is there a possibility to automate saving documents?

I always save in specific folder, so path can be defined in macro (desktop can be used as example) and I need to change file name before saving - I only add some text at the beginning (original name stays the same).

So lets say I have an worksheet called TEST. Marco needs to show box where user can add text which will be displayed at the beginning of worksheet name. So If user fills in "My file", worksheet is saved as "My file TEST" in specific folder.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I was able to crack it myself - here is code.

VBA Code:
Sub ChangeFilename()


    Dim NewName As String
        NewName = InputBox("Insert name", "Change file's name")
        
    Dim CurrentName As String
        CurrentName = ActiveWorkbook.Name
    
    Dim WS As Workbook
    Set WS = ActiveWorkbook
    
    ActiveWorkbook.Windows(1).Caption = NewName & " " & CurrentName
    
    WS.SaveAs "C:\Public\KRA\" & NewName & " " & CurrentName
    
    End Sub
 
Upvote 0
Solution
Thanks for sharing the solution!

Just one note, SaveAs will already change the workbook's window caption as soon as the file is saved, so there is no need for an extra step to change the caption property.
 
Upvote 0
Thanks for sharing the solution!

Just one note, SaveAs will already change the workbook's window caption as soon as the file is saved, so there is no need for an extra step to change the caption property.
Thanks, removed this line, learned something new!
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

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