# excel macro for printing and naming PDF files



## j-viking (Dec 16, 2011)

Anyone know if it would it be possible to create a printing macro that would print all sheets (or preferably all sheets that are highlighted) in a workbook. Each sheet should be printed to a separate PDF file and the name of the PDF file should be the "TAB-title" concatenated with the string value of one cell in the same sheet, say cell A1 for sake of simplicity.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

You can try this macro. 

```
Sub Macro1()

    Dim N As Long
    Dim fileString As String
    Dim cellValue As String
    
    With ActiveWindow.SelectedSheets
        For N = 1 To .Count
            Sheets(.Item(N).Name).Select
            cellValue = Trim(Sheets(.Item(N).Name).Range("A1").Value)
            fileString = .Item(N).Name & cellValue & ".pdf"
            Sheets(.Item(N).Name).ExportAsFixedFormat Type:=xlTypePDF, Filename:=fileString
        Next N
    End With

End Sub
```
It works in Excel 2007 and should work in 2010 as well.
Note in Excel 2007 you either need at least Office 2007 SP2 (or better Office 2007 SP3) or the SaveAs PDF Add-In to be able to save as PDF.

The macro looks for the sheets that are selected. Then saves each sheet as a seperate PDF document. The name of the document is the 
Sheets Name + Value of Cell A1 on that sheet + .PDF

If you have Office 2003 you will need a 3rd party PDF converter like PDFCreator or CutePDF (the Freeware one).
If this is the case let me know because the macro will have to change.


----------

