Saving file as returns error "424": object neccessary

confused in Frankfurt

Board Regular
Joined
Oct 11, 2010
Messages
53
Hi there,
I have a macro to create a worksheet and it is not saving the file returning the error 424.

In my code I define the folder and the file name.

Dim Folder As String
Folder = "A:\Controlling\2014\Reporting\CARS\Template\CARS\06_Jun\"

Dim RSM As String

Selection.Offset(0, 2).Select 'cell in file where RSM name
RSM = Selection

Dim timestamp As String
timestamp = Format(Date, "yyyymmdd")

Dim NBName As String
NBName = "CARS_" & RSM & timestamp & ".xlsm"

ActiveWorkbooks.SaveAs Filename:=Folder & NBName _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

when I scroll over the defined names in the last code it shows the following:


-- removed inline image ---


-- removed inline image ---

I am not sure why the file is not saving and which object is missing.

Regards
Sarah
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It should be ActiveWorkbook not ActiveWorkbooks.
 
Upvote 0
Should
Rich (BB code):
RSM = Selection


be

Rich (BB code):
RSM = Selection.value


Pete
 
Upvote 0
This works - I have created a new string for use as your filename.
Code:
    Dim Folder As String
    Folder = "A:\Controlling\2014\Reporting\CARS\Template\CARS\06_Jun\"
    
    Dim RSM As String
    
    Selection.Offset(0, 2).Select 'cell in file where RSM name
    RSM = Selection.formula
    
    Dim timestamp As String
    timestamp = Format(Date, "yyyymmdd")
    
    Dim NBName As String
    NBName = "CARS_" & RSM & timestamp & ".xlsm"
    
    '###Extra string created here
    Dim MyFileName As String
    MyFileName = Folder & NBName
         
    '###Extra string used as filename
    ActiveWorkbook.SaveAs Filename:=MyFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
 
Last edited:
Upvote 0
This works - I have created a new string for use as your filename.
Code:
    Dim Folder As String
    Folder = "A:\Controlling\2014\Reporting\CARS\Template\CARS\06_Jun\"
    
    Dim RSM As String
    
    Selection.Offset(0, 2).Select 'cell in file where RSM name
    RSM = Selection.formula
    
    Dim timestamp As String
    timestamp = Format(Date, "yyyymmdd")
    
    Dim NBName As String
    NBName = "CARS_" & RSM & timestamp & ".xlsm"
    
    '###Extra string created here
    Dim MyFileName As String
    MyFileName = Folder & NBName
         
    '###Extra string used as filename
    ActiveWorkbook.SaveAs Filename:=MyFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

now I must be going crazy as I still have the same error.

Maybe one note, the definitions are in different parts of the macro the Timestamp and folder are at the beginning outside of a loop, the other definitions are within the loop
 
Upvote 0
Well, wherever your lines of code appear, your original issue was that as well as Norie's suggestion to change ActiveWorkbooks to ActiveWorkbook, you need to create your filename by concatenating dates, cell contents and string values into one string variable, which you then use as a paramater in your ActiveWorkbook.Save command.
With things like this, I also ways find it handy to add MsgBoxes to my code, so you can see the values of variables as you go along. Try adding
Code:
MsgBox (MyFilename)
immediately before your ActiveWorkbook.Save command, so you can see which bits of your filename haven't been added in correctly. Without all the correct bits, it may amount to an invalid filename.

Of course, it always helps to post the relevant code in its entirety..! :)
 
Upvote 0

Forum statistics

Threads
1,215,973
Messages
6,128,042
Members
449,414
Latest member
sameri

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