Run-time '1004' Save

Copper Contributor

Hi all,

 

I'm having some issues with a Save As macro I'm trying to run. It is exactly the same code I use for a separate report (which works fine), however, on this one, I seem to continuously get the following message:

 

"Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed

 

I'm struggling to see what I am doing wrong in the code - can somebody please advise? The code should instruct it to save as per the specified strings. Code as below:

 

pedrohrmoreira_0-1592385913290.png

 

Many thanks,

Pedro M.

 

3 Replies

@pedrohrmoreira 

 

You should declare a String variable to hold the dynamic file name and assign dynamic file name to this variable and use debug.print to print the variable in the Immediate Window and see if the filename is a valid file name.

 

Dim strFileName As String

strFileName = strgenericfilepath & strpackingbranch & stryear & strmonth & strday & strfilename

Debug.Print strFileName

'SaveAs statement here

@Subodh_Tiwari_sktneer 

 

Thank you! :) 

@pedrohrmoreira 

You're welcome!