Jun 17 2020 02:27 AM
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:
Many thanks,
Pedro M.
Jun 17 2020 04:18 AM - edited Jun 17 2020 04:18 AM
Jun 17 2020 04:18 AM - edited Jun 17 2020 04:18 AM
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