Save .xltm as .xlsm problem

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
574
Office Version
  1. 365
Platform
  1. Windows
I have some code that launches when a cell is changed. The code breaks on the line below highlighted in red.

ActiveWorkbook.SaveAs Filename:=sFilename, FileFormat:=52

The error message reads: Run-time error '1004': The following solutions are listed: does folder exist? Is folder read only? Is name more than 218 characters? Make sure there are the following symbols are not in the name <>?[]:|or*.

None of these issues seem to apply unless I am missing something in the name formula. I don't know what the error is that I need to address.

Thanks for the help.

Robert

Rich (BB code):
 'Specify directory
            sPath = "\\Ferrari\common\Product QC\BioPrep QC\PrepaCyte-CB\PrepaCyte-CB QC\510k Lot Testing\Bag 3 Cryobag testing\" & Format(Date, "yyyy") & "\"
            SetAttr sPath, vbNormal
            
            If Dir(sPath, vbDirectory) = "" Then
    
                MkDir sPath

                ChDir sPath
        
                'Define Name
                sFilename = sPath & Format(Sheets("QC5003.17 Cryobag Testing Main").Range("E3").Value, "mm-dd-yy") & " Cryobag Testing on Origen LOT " & Sheets("QC5003.17 Cryobag Testing Main").Range("L3").Value & " by " & Sheets("QC5003.17 Cryobag Testing Main").Range("E2").Value & ".xlsm"
                
                SetAttr sFilename, vbNormal
                
                ActiveWorkbook.SaveAs Filename:=sFilename, FileFormat:=52
   
                'Displays a message box indicating the filename that was used top save the file.
                    MsgBox ("File was saved with the following name:" & Format(Sheets("QC5003.17 Cryobag Testing Main").Range("E3").Value, "mm-dd-yy") & " Cryobag Testing on Origen LOT " & Sheets("QC5003.17 Cryobag Testing Main").Range("L3").Value & " by " & Sheets("QC5003.17 Cryobag Testing Main").Range("E2").Value & ".xlsm")
   
            Else
                'Check to see if file already exists
                If ActiveWorkbook.Name = sFilename Then
                    ActiveWorkbook.Save
                    Exit Sub
                Else
                    ActiveWorkbook.SaveAs Filename:=sFilename, FileFormat:=52
                
 MsgBox ("File was saved with the following name:" & Format(Sheets("QC5003.17 Cryobag Testing Main").Range("E3").Value, "mm-dd-yy") & " Cryobag Testing on Origen LOT " & Sheets("QC5003.17 Cryobag Testing Main").Range("L3").Value & " by " & Sheets("QC5003.17 Cryobag Testing Main").Range("E2").Value & ".xlsm")
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Other than step into, run to cursor, add watch, quick watch, toggle break point, and remove break point, I cannot do anything to debug the code. Compile is not a viable selection. When I step into the macro, it flags on the same line.

At a loss.

Robert
 
Upvote 0
Put "Debug.Print sFilename" in the code right after you set sFilename, then step through to that point. When you get past it the sFilename string will be written to the Immediate Window where you can check and see if it passes muster as a valid string.
 
Upvote 0
I moved a couple of things around and now it is working. Thanks for the help.

Robert
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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