Hi all.
My friend wrote me a macro to export data in templates to PDFs. Simple enough task, but neither of us can get it to work on my Mac. Is it possible to do so? Code below. Thanks in advance!
Sub GetDataGenerateInvoices()
Dim DealerCounter As Integer
Dim DealerCodePos As Integer
Dim strFile As String
Dim strPathFile As String
Dim strSheet As String
Dim strInvoiceTemplate As String
Dim MasterBook As Workbook
Dim SourceBook As Workbook
Dim rngSourceRange As Range
Dim rngDestination As Range
Set MasterBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set SourceBook = ActiveWorkbook
'Get sales data and copy
Set rngSourceRange = Application.Range("Current!A6:F3000")
MasterBook.Activate
Set rngDestination = Application.Range("Current!A6")
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
'Get invoice numbers and copy
SourceBook.Activate
Set rngSourceRange = Application.Range("Current!AB4:AB50")
MasterBook.Activate
Set rngDestination = Application.Range("Current!AB4")
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
'Get addresses and copy
SourceBook.Activate
Set rngSourceRange = Application.Range("Addresses!A5:B100")
MasterBook.Activate
Set rngDestination = Application.Range("Addresses!A5")
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
SourceBook.Close False
End If
End With
'create and save invoice for all dealer codes
For DealerCounter = 1 To Worksheets("Invoice 1").Range("K18").Value
'used to cycle through the unique dealer codes
DealerCodePos = DealerCounter + 3
If Not Worksheets("Current").Range("AA" & DealerCodePos).Value = "RM" Then
'change dealer code in worksheet
Worksheets("Current").Range("P6").Value = Worksheets("Current").Range("AA" & DealerCodePos).Value
'wait 2 seconds to allow update of cells
Application.Wait (Now + TimeValue("0:00:00"))
'create PDF file name
strFile = Worksheets("Invoice 1").Range("F10").Value & ".pdf"
strPathFile = ActiveWorkbook.Path & "" & strFile
'choose which invoice template to use
strSheet = Worksheets("Invoice 1").Range("L18").Value
strInvoiceTemplate = "Invoice " & strSheet
'export to PDF
Worksheets(strInvoiceTemplate).ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next
End Sub
My friend wrote me a macro to export data in templates to PDFs. Simple enough task, but neither of us can get it to work on my Mac. Is it possible to do so? Code below. Thanks in advance!
Sub GetDataGenerateInvoices()
Dim DealerCounter As Integer
Dim DealerCodePos As Integer
Dim strFile As String
Dim strPathFile As String
Dim strSheet As String
Dim strInvoiceTemplate As String
Dim MasterBook As Workbook
Dim SourceBook As Workbook
Dim rngSourceRange As Range
Dim rngDestination As Range
Set MasterBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set SourceBook = ActiveWorkbook
'Get sales data and copy
Set rngSourceRange = Application.Range("Current!A6:F3000")
MasterBook.Activate
Set rngDestination = Application.Range("Current!A6")
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
'Get invoice numbers and copy
SourceBook.Activate
Set rngSourceRange = Application.Range("Current!AB4:AB50")
MasterBook.Activate
Set rngDestination = Application.Range("Current!AB4")
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
'Get addresses and copy
SourceBook.Activate
Set rngSourceRange = Application.Range("Addresses!A5:B100")
MasterBook.Activate
Set rngDestination = Application.Range("Addresses!A5")
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
SourceBook.Close False
End If
End With
'create and save invoice for all dealer codes
For DealerCounter = 1 To Worksheets("Invoice 1").Range("K18").Value
'used to cycle through the unique dealer codes
DealerCodePos = DealerCounter + 3
If Not Worksheets("Current").Range("AA" & DealerCodePos).Value = "RM" Then
'change dealer code in worksheet
Worksheets("Current").Range("P6").Value = Worksheets("Current").Range("AA" & DealerCodePos).Value
'wait 2 seconds to allow update of cells
Application.Wait (Now + TimeValue("0:00:00"))
'create PDF file name
strFile = Worksheets("Invoice 1").Range("F10").Value & ".pdf"
strPathFile = ActiveWorkbook.Path & "" & strFile
'choose which invoice template to use
strSheet = Worksheets("Invoice 1").Range("L18").Value
strInvoiceTemplate = "Invoice " & strSheet
'export to PDF
Worksheets(strInvoiceTemplate).ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next
End Sub