+ Reply to Thread
Results 1 to 15 of 15

With excel to print a selected page from a word document

  1. #1
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    With excel to print a selected page from a word document

    Hi! Everybody

    I'm a new user in excel vba. Anyone can help me?

    With excel , I want to print the second page of a 5 pages word document


    Sub Macro1()

    Dim objWord
    Dim objDoc
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("c:\xxx.doc")
    objWord.Visible = True
    objDoc.PrintOut Pages:="2"
    objWord.Quit

    End Sub


    What's wrong with the above ?
    It printed all the pages, not the second.

    Thanks!

  2. #2
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13
    Posts
    976

    Re: With excel to print a selected page from a word document

    Hi eb4927,

    From what you're saying you're almost there.

    Have you tried removing the line;

    Please Login or Register  to view this content.
    Remember you are unique, like everyone else

  3. #3
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    Re: With excel to print a selected page from a word document

    Dear noboffinme,

    if removing the line [objDoc.PrintOut Pages:="2" ]
    it will print all the pages

    I only want to print the second page
    Any suggestion?

    Thanks!

  4. #4
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13
    Posts
    976

    Re: With excel to print a selected page from a word document

    OK, how about the opposite.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    Re: With excel to print a selected page from a word document

    thanks
    Let me try

  6. #6
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    Re: With excel to print a selected page from a word document

    Still can't print a selected page from a word document.

    Anyone help me

  7. #7
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13
    Posts
    976

    Re: With excel to print a selected page from a word document

    OK, what happens if you change the "2" to "4"

    I'm just testing the behaviour of your code.

    If you get any errors, let me know what they are.

    Thanks

  8. #8
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    Re: With excel to print a selected page from a word document

    if I change the page no, no error shown, it works
    but it prints all the pages
    I just only want to print one page

  9. #9
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13
    Posts
    976

    Re: With excel to print a selected page from a word document

    OK, I recorded a Macro on my PC.

    I'm using Office 2010 with Windows 7.

    Please Login or Register  to view this content.
    This works correctly, just printing pages 1,3,4 & 5.

  10. #10
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    Re: With excel to print a selected page from a word document

    Hi noboffinme

    Thanks!

  11. #11
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: With excel to print a selected page from a word document

    Please Login or Register  to view this content.
    ???
    If your questions has been answered to your satisfaction please don't forget to do the following:

    Add Reputation ... and ... Mark Thread as Solved

    Thanks,

    Ma 10:8b Freely you have received; freely give.

  12. #12
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    Re: With excel to print a selected page from a word document

    Hi Everybody

    I'm writing a excel file. The excel file have several parts. I want to write a click command with the help of vba to open a word document in background and then print one of the pages. I tried the following, but it printed all pages.


    Sub Macro1()
    Dim objWord
    Dim objDoc
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("c:\xxx.doc")
    objWord.Visible = True
    objDoc.PrintOut Pages:="2"
    objWord.Quit
    End Sub



    Sub Macro2()
    Dim objWord
    Dim objDoc
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("c:\xxx.doc")
    objWord.Visible = True
    objDoc.PrintOut From:="2", to:="2"
    objWord.Quit
    End Sub

  13. #13
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: With excel to print a selected page from a word document

    Try
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    09-04-2014
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    8

    Re: With excel to print a selected page from a word document

    Still fail to print one page

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13
    Posts
    976

    Re: With excel to print a selected page from a word document

    Try recording a Macro while you print a document & select certain pages before you hit 'Print'.

    Compare that code with the recorded code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Set print area of selected range then print preview if ok then print the document!
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 07:10 AM
  2. Replies: 1
    Last Post: 01-30-2014, 05:38 PM
  3. Print off the word document using excel vba code
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2013, 09:42 AM
  4. How do I embed a two page word document in excel
    By GregM in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-12-2006, 11:30 PM
  5. Automating Word - Print one page not entire document!
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2005, 03:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1