• Macro: print each sheet to pdf using sheet name as (Excel 97 sr-2 Win95)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Macro: print each sheet to pdf using sheet name as (Excel 97 sr-2 Win95)

    Author
    Topic
    #378040

    Has anybody a macro that will print each sheet in a workbook to a seperate file using the sheet name as the file name? I need to produce a pdf file for each sheet. I have full Acrobat and at present am printing each sheet by hand to PDFMaker.

    Many thanks,

    David

    Viewing 0 reply threads
    Author
    Replies
    • #624570

      First, you must find out the exact name of the PDFMaker “printer”. In any workbook, select File/Print… and set the printer to PDFMaker. You don’t have to click OK, you can cancel the command.
      Now, activate the Visual Basic Editor and open the Immediate window (Ctrl+G). Type
      ? Application.ActivePrinter
      Write down or copy the exact name. It will probably be something like “PDFMaker on LPT0:” (without the quotes)

      Create a macro:

      Sub PrintSheetsToPDF()
      Dim wbk As Workbook
      Dim sht As Worksheet
      Set wbk = ActiveWorkbook ‘ or any workbook
      For Each sht In wbk.Worksheets
      SendKeys “C:” & sht.Name & “{ENTER}”
      sht.PrintOut PrintToFile:=True, ActivePrinter:=”PDFMaker on LPT0:”
      Next sht
      End Sub

      Substitute the name you wrote down or copied for the ActivePrinter argument.

      Note: SendKeys is used as a workaround because Microsoft states that you can’t supply the file name in VBA.

      • #624573

        Many thanks Hans – worked a treat. I just have to fine-tune the SendKeys to get then in the right directory.

        However I am going to be sent a large number of workbooks every month to convert – is there any way of tying the macro to Excel instead of a particular workbook – as in normal.dot in Word? I don’t want to have to paste the macro into every workbook.

        David

        • #624587

          put it in the “personal.xls” file in XLStart

          Steve

        • #624588

          To have a macro available all the time, you can put it in Personal.xls. See the Personal.xls Tutorial by Legare Coleman.

          If you wish, you can assign the macro to a toolbar button.

          • #624771

            Thanks to everybody for the help – I’ve just rattled through about 500 sheets producing 2-page pdf files in a couple of minutes.

            David

    Viewing 0 reply threads
    Reply To: Macro: print each sheet to pdf using sheet name as (Excel 97 sr-2 Win95)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: