Saving as a macro enabled workbook using VBA code

Psiduke

New Member
Joined
Sep 30, 2011
Messages
5
right ho,

may be incredibly straightforward this (I hope it is) I'm using excel 2007 - i've created a macro enabled template file, and I'm wanting to include some code that will allow me to automatically save in a folder location using the name from a cell, but I still want to be able to use macros in the saved spreadsheet, i assumed it would be a simple case of changing the file extension to .xlsm, but this returns an error, i can get the file to save as a standard workbook, so i'm a bit lost - below is the code i've been using

Sub SaveBook()
Dim sFile As String
sFile = Range("J8") & ".xlsx"
ActiveWorkbook.SaveAs Filename:="O:\Mobile Plant\General\Budgeting & part expenditure\" & sFile
End Sub


any help most appreciated!

Cheers
 

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

Code:
Sub SaveBook()
Dim sFile As String
sFile = Range("J8").Value & ".xlsm"
ActiveWorkbook.SaveAs Filename:="O:\Mobile Plant\General\Budgeting & part expenditure\" & sFile, FileFormat:=52
End Sub
 
Upvote 0
Welcome to MrExcel.

Try:

Code:
ActiveWorkbook.SaveAs Filename:="O:\Mobile Plant\General\Budgeting & part expenditure\" & sFile, FileFormat:=52

In Excel 2007-2010, SaveAs requires both the FileFormat parameter and the correct file extension.
 
Upvote 0
Both of the FileFormat:=52 return a Run-time error '1004'

method 'saveAs' of object '_Workbook' failed

at a loss??
 
Upvote 0
J8 is the name that I want the spreadsheet to save as, it's Week commencing and then the date 13.10.11
 
Upvote 0
Then maybe

Code:
Sub SaveBook()
Dim sFile As String
sFile = "Week commencing " & Format(Date, "dd-mm-yy") & ".xlsm"
ActiveWorkbook.SaveAs Filename:="O:\Mobile Plant\General\Budgeting & part expenditure\" & sFile, FileFormat:=52
End Sub
 
Upvote 0
that does work thanks, but i need it to refer to the cell reference as part of the save name,

sorry to be a pain....
 
Upvote 0
that's sorted it thanks, although i'm also using the other coding VoG now too on a different sheet!

Cheers guys
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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