Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stuck on the last bit of code... (Word97 SR2 Win95)

    I've almost finished a bit of code for printing each page of a document to a pdf file. I've adapated a script by Roy Walter and it works except that I cannot get the syntax right for selecting the page number. The code is:

    Sub print_pages_pdf()

    Dim svFileToPrint As String

    Dim page_num As Integer

    page_num = ActiveDocument.BuiltInDocumentProperties(wdPropert yPages)


    SetPrinter:
    currentPrinter = Application.ActivePrinter
    Application.ActivePrinter = "Acrobat PDFWriter"

    SetStaticIniValues:
    svPDFIni = "c:windowssystempdfwritr.ini"

    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "cpmarginwhole") = "0"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "cpmarginpart") = "0"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "cpunits") = "2"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "custom") = "1"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "bDocInfo") = "0"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "bExecViewer") = "0"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "cpheightwhole") = "841"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "cpwidewhole") = "595"
    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "orient") = "1"


    For i = 1 To page_num

    svPdfName = "d:batcher" & "testing again " & i & ".pdf"


    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "PDFFilename") = svPdfName
    ActiveDocument.PrintOut Background:=0, Range:=wdPrintRangeOfPages, outputFilename:="", _
    Item:=wdPrintDocumentContent, Copies:=1, Pages:="3", PageType:=wdPrintAllPages, PrintToFile:=False, Collate:=False

    Next i

    End Sub

    I want to replace the Pages:="3" with some thing like Pages:= i so that the page to be printed is incrementated by 1 each time.. I've tried brackets, no brackets...

    Can someone give me a pointer please?

    Many thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stuck on the last bit of code... (Word97 SR2 Win95)

    You must surround the page number i in quotes; to include quotes in a string in code, use Chr(34):

    Pages:=Chr(34) & i & Chr(34)

  3. #3
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stuck on the last bit of code... (Word97 SR2 Win95)

    Hi Hans,

    Still getting an error "Invalid print range" - code looks like this:

    For i = 1 To page_num

    svPdfName = "d:batcher" & "testing again " & i & ".pdf"


    System.PrivateProfileString(svPDFIni, "Acrobat PDFWriter", "PDFFilename") = svPdfName
    ActiveDocument.PrintOut Background:=0, Range:=wdPrintRangeOfPages, outputFilename:="", _
    Item:=wdPrintDocumentContent, Copies:=1, Pages:=Chr(34) & i & Chr(34), PageType:=wdPrintAllPages, PrintToFile:=False, Collate:=False

    Next i

    Many thanks,

    David

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stuck on the last bit of code... (Word97 SR2 Win95)

    Either remove Range:=wdPrintRangeOfPages or replace it by Range:=wdPrintAllDocument.

  5. #5
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stuck on the last bit of code... (Word97 SR2 Win95)

    Printing okay now except... It prints the correct number of files, say 5 for a five-page document, but instead of printing page 1 in file 1, page 2 in file 2 etc it prints 5 files containg all the pages.

    Think it's time for coffee.

    Regards,

    David

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stuck on the last bit of code... (Word97 SR2 Win95)

    I'm sorry, I should have caught that. The following seems to work OK - please test carefully:

    ActiveDocument.PrintOut _
    Background:=0, Range:=wdPrintRangeOfPages, OutputFilename:="", _
    Item:=wdPrintDocumentContent, Copies:=1, Pages:=CStr(i), _
    PageType:=wdPrintAllPages, PrintToFile:=False, Collate:=False

    Range:=wdPrintRangeOfPages is back, but now, the page number is converted to a string by using CStr(i).

  7. #7
    Star Lounger
    Join Date
    Mar 2001
    Location
    St Georges du Bois, Pays de la Loire
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stuck on the last bit of code... (Word97 SR2 Win95)

    Yes!!!

    Don't apologise Hans - I salute you. I worried away all yesterday afternoon trying to make it work.

    Many thanks - treat yourself to a coffee and a cake.

    Regards,

    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •