vba code to use cell contents as filename

romantomson

New Member
Joined
Jul 8, 2018
Messages
8
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2010
Platform
  1. Windows
I currently have a macro enabled workbook named "Active Template.xlsm". The contents of cell C1 are in text format :
"2018 Matchplay Championship Draw"
I have a Close button and need the vba code for this button so that when clicked it will save the workbook (as a macro enabled workbooK) as :
path : C:\ Users\Roman\Documents\Competitions
filename :
2018 Matchplay Championship Draw
i.e Save As :
C:\ Users\Roman\Documents\Competitions\
2018 Matchplay Championship Draw.xlsm
<strike></strike>
I would appreciate any help to create the required vba code.
Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try this.
Code:
Dim strFileName As String
Dim strPath As String

    strPath =  "C:\ Users\Roman\Documents\Competitions\"
    strFileName = Sheets("Sheet1").Range("C1").Value & ".xlsm"  ' change Sheet1 to the sheet where C1 has the filename

    ActiveWorkbook.SaveAs strPath & strFileName, 52
 
Upvote 0
Code:
  ThisWorkbook.SaveAs Filename:="C:\Users\Roman\Documents\Competitions\" & _
                                Worksheets("thatSheetName").Range("C1").Value, _
                      FileFormat:=xlOpenXMLWorkbookMacroEnabled
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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