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
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