Excel macro to print a section from word

  • Hi


    I use Excel to open word documents and print the word document. I use this code to open word and to print it.


    Code
    1. Set wdApp = CreateObject("Word.Application")
    2. wdApp.documents.Open Filename:=aNameAndPath & Filename
    3. wdApp.Visible = True
    4. wdApp.ActiveDocument.PrintOut , Copies:=1


    Now i have word documents that is divide into Sections. I would like to find a code so that it's only Section 2 in the word document that is been printed.


    Thank you in advance.


    Alring

  • Re: Excel macro to print a section from word


    Add, after 'wdApp.Visible...'


    Code
    1. Dim Rng As Object
    2. Set Rng = wdApp.ActiveDocument.Range
    3. Rng.Sections(2).Range.Select
    4. '// Range:=1 would be Range:=wdSelection if using Early Binding.
    5. wdApp.ActiveDocument.PrintOut Range:=1, Copies:=1


    Untested, typed on a mobile phone, but probably works... :)

  • Re: Excel macro to print a section from word


    Hi cytop


    Thank you for the help. It works perfect.
    Maybe it's my word that now have a problem because if a section is on 2 pages then there come 3 pages out of the printer.
    But the macro works. THANK YOU.