Riku and the beat
Riku Seppälä

I create stuff and work as a VC. Aim for game-changing things.
Co-founder of Aaltoes and Startupifier and a couple of companies.

Search

December 8th, 8:34am 0 comments

Printing multiple PDF's in excel with VBA

I noticed there are no really good resources for learning VBA on the web, so I'm sharing some simple code snippets.

I have created a workbook with about 50 automatically updating sheets, and I need to print them as pdf's. So I quickly created a VBA script to do this. 

What this code does is that it prints sheets nr 9-39 with the filename "MyFile_" + [name of the sheet] in the folder where the workbook in question is located.

Code:

Public Sub printPrivateInvestorPDFs()

    Dim FilName As String

    For Count = 9 To 39 Step 1

        Sheets(Count).Activate

        FilName = "MyFile_" + ActiveSheet.Name

        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FilName + ".pdf", Quality:=xlQualityStandard, From:=1, To:=3, OpenAfterPublish:=True

    Next Count

End Sub

 

 

For getting help with VBA problems, I found this user group really helpful: https://groups.google.com/forum/#!forum/excel-macros

Posted