PDA

View Full Version : Mac VBA to create a folder and print pdfs in folder



s_fussnecker
01-12-2019, 05:57 PM
I have the following code written and working on a PC, but I need it to work on a Mac. I am not a Mac user, so I do not know the differences in VBA coding on a Mac vs. PC. I need the code to cycle through a list from one sheet to fill in and print a 2nd sheet to pdf. There will be around 300 different pdfs that I need created in a new folder in the same location as the spreadsheet. The line of code it is currently hanging up on is the set fdObj, but I'm not sure what else will not run correctly on a Mac. Thanks for any help


Option Explicit

Sub PrintAnnual()

Dim i, j, holder, fin

Sheets("Invoice").Activate
Worksheets("Invoice").Range("C11").Value = "December"

Dim WS_Total As Integer
WS_Total = ActiveWorkbook.Worksheets.Count - 2
fin = Worksheets(WS_Total).Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count - 1

Dim folder As String
folder = ActiveWorkbook.Path + "\Year End Invoices\"

Dim fdObj As Object
Application.ScreenUpdating = False
Set fdObj = CreateObject("Scripting.FileSystemObject")

fdObj.CreateFolder (folder)

Application.ScreenUpdating = True

For j = 2 To fin

Worksheets("Invoice").Range("C9").Value = Worksheets(WS_Total).Cells(j, 1)
Sheets("Invoice").Activate
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=folder + Worksheets("Invoice").Range("C9") + " Year End Invoice", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=1, _
OpenAfterPublish:=False

Next j

End Sub

jvbeaupre
01-13-2019, 04:18 PM
Check the May-June 2018 items at this website:

http://www.rondebruin.nl/whatsnew.htm

There's lots of good stuff elsewhere on that site too!