run time error 424

Phone_Guy

New Member
Joined
Nov 5, 2009
Messages
19
I'm trying to save this file to "today's" date with a macro. I'm now getting a 424 run time error. I'm very new to VBA , so I was wondering if someone can tell me what I'm doing wrong in this code? It's pieced together from code I've found in forums and changed a little. Also can you recommend any good books to learn more about VBA? Thanks for any help.


Sub RDB_Worksheet_Or_Worksheets_To_PDF_And_Create_Mail()
Dim FileName As String
Dim Today As Date


If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"be aware that every selected sheet will be published"
End If

'Call the function with the correct arguments
'Tip: You can also use Sheets("Sheet3") instead of ActiveSheet in the code(sheet not have to be active then)
FileName = RDB_Create_PDF(ActiveSheet, "C:\Documents and Settings\safety2\Desktop\" & Format(Today, "MM_DD_YYYY").pdf, True, False)

'For a fixed file name and overwrite it each time you run the macro use
'RDB_Create_PDF(ActiveSheet, "C:\Users\Ron\Test\YourPdfFile.pdf", True, True)

If FileName <> "" Then


RDB_Mail_PDF_Outlook FileName, Range("g11"), "Time Sheet", _
"See the attached PDF file for daily time sheet" _
& vbNewLine & vbNewLine & "", True
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Is the error on the line beginning FileName = ...?

If it is I think it's because you appear to be trying to use some property called pdf.

That definitely doesn't exist, especially not for a string which is what Format returns.:)

Try this.
Code:
Filename = RDB_Create_PDF(ActiveSheet, "C:\Documents and Settings\safety2\Desktop\" & Format(Today, "MM_DD_YYYY") & ".pdf", True, False)
 
Upvote 0
Thank you!! Someday I'll figure this stuff out. With the "today" command what clock does it reference? It just saved as 1230 1899. The computer clock is correct. Any ideas?
 
Upvote 0
Sorry, I figured it out... I had to add "Today = Date" below Dim Today as Date. Thanks again for your help.
 
Upvote 0
The reason you were getting the date as 1230 1899 was because you hadn't given Today a value so it would be regarded as 0 or empty.:)

You could just use Date - you don't need to have a variable for the date, though it might be a good idea if you are using it for other things.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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