• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Saving a file using vba

mr_hiboy

Member
Hi,


I'm trying to save a file in a location, I'd like the "Month" sub folder to be taken from a cell in the file, i.e. May, June. So instead of month it would be "A1" for example?


ActiveWorkbook.SaveAs Filename:= _

"C:FolderSubfolderMONTHfile.xls"

, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False


thanks
 
You can concatenate the cell's value into the string:

[pre]
Code:
ActiveWorkbook.SaveAs _
Filename:="C:FolderSubfolder" & ActiveWorkbook.Worksheets("Sheet1").Range("A1").Value & "file.xlsx", _
FileFormat:=xlOpenXMLWorkbook, _
CreateBackup:=False
[/pre]
Note the FileFormat and the file extension: xlOpenXMLWorkbook is xlsx. Saving in this format will remove any VBA code from the file. If you want to retain VBA code then save as xlOpenXMLWorkbookMacroEnabled with an xlsm extension.
 
Thanks for quick reply, unfortunately when I try use it, not working. I'll provide my full line in case that makes a difference.


ActiveWorkbook.SaveAs Filename:= _

"C:ReportsWeeklyReports" & ActiveWorkbook.Worksheets("Summary").Range("D77").Value & "2013 Touring Weekly Revenue - " & Format(Now - 1, "DD-MMM-YY") _

, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False


The last bit datestamping it. It works fine if I just use text "May"


thanks
 
Back
Top