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
    Set wdApp = CreateObject("Word.Application")
        wdApp.documents.Open Filename:=aNameAndPath & Filename
            wdApp.Visible = True
    
    
        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
    Dim Rng As Object
    Set Rng = wdApp.ActiveDocument.Range
    Rng.Sections(2).Range.Select
    '// Range:=1 would be Range:=wdSelection if using Early Binding.
    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.

  • Re: Excel macro to print a section from word


    Quote

    if a section is on 2 pages then there come 3 pages...


    Check for an embedded page break or the section formatted with page break after.

  • Re: Excel macro to print a section from word


    It seems to be OK. But any way thenak you for the help.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!