Hi All,
I'm trying to print PDF files from a specific sheet within excel.
The below code works perfectly on a Windows machine but I can't get it working on my Mac. Everytime I run, I get an error code (1004). Do I need to edit the code to be compatible with Mac OS? Can anyone spot any glaring issues?
Thanks a lot.
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993}span.s1 {color: #011993}span.s2 {color: #000000}</style>Sub GenerateInvoices()
Dim DealerCounter As Integer
Dim DealerCodePos As Integer
Dim strFile As String
Dim strPathFile As String
Dim strSheet As String
Dim strInvoiceTemplate As String
'create and save invoice for all dealer codes
For DealerCounter = 1 To Worksheets(1).Range("M2").Value
'used to cycle through the unique dealer codes
DealerCodePos = DealerCounter + 1
'change dealer code in worksheet
Worksheets(1).Range("E1").Value = Worksheets(1).Range("L" & DealerCodePos).Value
'wait 2 seconds to allow update of cells
Application.Wait (Now + TimeValue("0:00:02"))
'create PDF file name
strFile = Worksheets(1).Range("J2").Value & ".pdf"
strPathFile = ActiveWorkbook.Path & "" & strFile
'choose which invoice template to use
strSheet = Worksheets(1).Range("I2").Value
strInvoiceTemplate = "InvoiceTemplate" & strSheet
'export to PDF
Worksheets(strInvoiceTemplate).ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next
End Sub
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993}span.s1 {color: #011993}span.s2 {color: #000000}</style>
I'm trying to print PDF files from a specific sheet within excel.
The below code works perfectly on a Windows machine but I can't get it working on my Mac. Everytime I run, I get an error code (1004). Do I need to edit the code to be compatible with Mac OS? Can anyone spot any glaring issues?
Thanks a lot.
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993}span.s1 {color: #011993}span.s2 {color: #000000}</style>Sub GenerateInvoices()
Dim DealerCounter As Integer
Dim DealerCodePos As Integer
Dim strFile As String
Dim strPathFile As String
Dim strSheet As String
Dim strInvoiceTemplate As String
'create and save invoice for all dealer codes
For DealerCounter = 1 To Worksheets(1).Range("M2").Value
'used to cycle through the unique dealer codes
DealerCodePos = DealerCounter + 1
'change dealer code in worksheet
Worksheets(1).Range("E1").Value = Worksheets(1).Range("L" & DealerCodePos).Value
'wait 2 seconds to allow update of cells
Application.Wait (Now + TimeValue("0:00:02"))
'create PDF file name
strFile = Worksheets(1).Range("J2").Value & ".pdf"
strPathFile = ActiveWorkbook.Path & "" & strFile
'choose which invoice template to use
strSheet = Worksheets(1).Range("I2").Value
strInvoiceTemplate = "InvoiceTemplate" & strSheet
'export to PDF
Worksheets(strInvoiceTemplate).ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next
End Sub
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008f00}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993}span.s1 {color: #011993}span.s2 {color: #000000}</style>