Hi All,
I am working on a macro the will open a workbook, send the first sheet as a pdf and then save and close the workbook. This is what I have so far after pilfering other variations.
As a Noob to macros I am struggling to get this to work.
Any help would be appreciated.
I am working on a macro the will open a workbook, send the first sheet as a pdf and then save and close the workbook. This is what I have so far after pilfering other variations.
Code:
Sub Send_Reports()
'
' Send_Reports Macro
Dim sh As Worksheet
Dim TempFilePath As String
Dim TempFileName As String
Dim FileName As String
ChDir "K:\Reports\Store Reports\Store Reports\NSW"
Workbooks.Open FileName:="K:\Reports\Store Reports\Store Reports\NSW\081.xls"
'Temporary path to save the PDF files
TempFilePath = Environ$("temp") & "\"
'Loop through every worksheet
For Each sh In ThisWorkbook.Worksheets
FileName = ""
'Test A1 for a mail address
If sh.Range("A1").Value Like "?*@?*.?*" Then
'If there is a mail address in A1 create the file name and the PDF
TempFileName = TempFilePath & sh.Name & Format(Now, "dd-mmm-yy h-mm-ss") & ".pdf"
FileName = RDB_Create_PDF(sh, TempFileName, True, False)
'If publishing is OK create the mail
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileName, sh.Range("A1").Value, "TGGIS Report " & Format(Now, "dd-mmm-yy"), _
"See the attached PDF file with the latest data" _
& vbNewLine & vbNewLine & "Regards The Good Guys Installation Service", False
'After the mail is created delete the PDF file in TempFilePath
If Dir(TempFileName) <> "" Then Kill TempFileName
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & 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 If
Next sh
ActiveWorkbook.Save
ActiveWindow.Close
As a Noob to macros I am struggling to get this to work.
Any help would be appreciated.