Creating a file in VBA Macro and saving it in a specific location

anshikam

Board Regular
Joined
Aug 20, 2016
Messages
87
Hello,
Trying to create a file and save it in a specific location with the below code.

Error code I get is :

Run Time Error '424'
Object Required


Report = "RMC_Indemnity_Report" & a & " " & b & c & d & ".xls"
Dim Path As String
Path = "F:\Corporate\Anshika\Due Dates\sent\"

Workbooks.Add
ActiveWorkbooks.SaveAs Path & "\" & Report
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi
Try
VBA Code:
Sub test()
    Report = "RMC_Indemnity_Report" & "a" & " " & "b" & "c" & "d" & ".xls"
    Dim Path As String
    Path = "F:\Corporate\Anshika\Due Dates\sent"
    Workbooks.Add
    ActiveWorkbook.SaveAs Path & "\" & Report
End Sub

So "\" is doubled one of them should be deleted "path"f:.....\sent"
then ActiveWorkbook.save as not ActiveWorkbooks
 
Upvote 0
Hi
Try
VBA Code:
Sub test()
    Report = "RMC_Indemnity_Report" & "a" & " " & "b" & "c" & "d" & ".xls"
    Dim Path As String
    Path = "F:\Corporate\Anshika\Due Dates\sent"
    Workbooks.Add
    ActiveWorkbook.SaveAs Path & "\" & Report
End Sub

So "\" is doubled one of them should be deleted "path"f:.....\sent"
then ActiveWorkbook.save as not ActiveWorkbooks
Sorry my bad.
However fixing this still gives me an error:

Run Time Error '424'
Object Required

Report = "RMC_Indemnity_Report" & a & " " & b & c & d & ".xls"
Dim Path As String
Path = "F:\Corporate\Anshika\Due Dates\sent\"
Workbooks.Add
ActiveWorkbooks.SaveAs Path & Report
 
Upvote 0
You still having
VBA Code:
ActiveWorkbooks.SaveAs Path & Report
VBA Code:
ActiveWorkbook.SaveAs Path & Report
And What about a, b, c, and d
 
Upvote 0
You still having
VBA Code:
ActiveWorkbooks.SaveAs Path & Report
VBA Code:
ActiveWorkbook.SaveAs Path & Report
And What about a, b, c, and d
This is oly part of a larger code...a b c d is the Date Time Stamp since i do not want to overwrite the earlier file.
Updated code has been fixed please see below. Same issue....


Dim Report As String
Dim a As Date
Dim b As Integer
Dim c As Integer
Dim d As Integer

a = Date
b = Hour(Now())
c = Minute(Now())
d = Second(Now())

'MsgBox a & b & c & d
Report = "RMC_Indemnity_Report" & a & " " & b & c & d & ".xls"
'MsgBox report
Dim Path As String
Path = "F:\Corporate\Anshika\Due Dates\sent\"

Workbooks.Add
ActiveWorkbooks.SaveAs Path & Report
 
Last edited:
Upvote 0
Ok that's fine for a b c d
Then ActiveWorkbook without "s" at the end
 
Upvote 0
I h
This is only part of a larger code...a b c d is the Date Time Stamp since i do not want to overwrite the earlier file.
Updated code has been fixed please see below. Same issue....


Dim Report As String
Dim a As Date
Dim b As Integer
Dim c As Integer
Dim d As Integer

a = Date
b = Hour(Now())
c = Minute(Now())
d = Second(Now())

'MsgBox a & b & c & d
Report = "RMC_Indemnity_Report" & a & " " & b & c & d & ".xls"
'MsgBox report
Dim Path As String
Path = "F:\Corporate\Anshika\Due Dates\sent\"

Workbooks.Add
ActiveWorkbooks.SaveAs Path & Report
I had my system changed and these codes have been working fine for months.....let me look at this again however earlier i was Adding and saving the file in 1 statement and it worked just fine.

Workbooks.Add.SaveAs Filename:=Report
 
Upvote 0
Right
If the the date something like "05/11/2020"
will not work as a part of file name
What you could do

VBA Code:
Dim a as String
.
.
.
a=Date
a=Replace(a, "/", "_")
 
Upvote 0
Right
If the the date something like "05/11/2020"
will not work as a part of file name
What you could do

VBA Code:
Dim a as String
.
.
.
a=Date
a=Replace(a, "/", "_")
Right
If the the date something like "05/11/2020"
will not work as a part of file name
What you could do

VBA Code:
Dim a as String
.
.
.
a=Date
a=Replace(a, "/", "_")
Have fixed the filename.....that was working just fine even before. The error I get is at the last line ActiveWorkbooks.SaveAs Path & Report.

Dim Report As String
Dim CDateTime As String
CDateTime = Day(Now()) & Month(Now()) & Year(Now()) & "_" & Hour(Now()) & Minute(Now()) & Second(Now())
Report = "RMC_Indemnity_Report" & CDateTime & ".xls"
Dim Path As String
Path = "F:\Corporate\Anshika\Due Dates\sent\"

Workbooks.Add
ActiveWorkbooks.SaveAs Path & Report
 
Upvote 0
Hi
Try
VBA Code:
Sub test()
    Report = "RMC_Indemnity_Report" & "a" & " " & "b" & "c" & "d" & ".xls"
    Dim Path As String
    Path = "F:\Corporate\Anshika\Due Dates\sent"
    Workbooks.Add
    ActiveWorkbook.SaveAs Path & "\" & Report
End Sub

So "\" is doubled one of them should be deleted "path"f:.....\sent"
then ActiveWorkbook.save as not ActiveWorkbooks
ok Finally this worked with Workbooks.Add.SaveAs Filename:=Path & Report

Thanks for all your help.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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