Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    I need some VBA to navigate from Word User Form to word.docm.
    I was using this method before from my excel user form

    Code:
    Set wordapp = CreateObject("Word.Application")
    Set worddoc = wordapp.Documents.Open(T & "\Inspection Reports\Cover Page.docm")
    	wordapp.Visible = True

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    In a userform in Word itself you don't have to create a Word.Application object, and neither do you need to make the application visible. The code would become

    Set worddoc = Documents.Open(T & "\Inspection Reports\Cover Page.docm")

  3. #3
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    [quote name='HansV' post='788267' date='10-Aug-2009 07:27']In a userform in Word itself you don't have to create a Word.Application object, and neither do you need to make the application visible. The code would become

    Set worddoc = Documents.Open(T & "\Inspection Reports\Cover Page.docm")[/quote]

    Thank you HansV

  4. #4
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    [quote name='ababenchrist' post='788270' date='10-Aug-2009 07:30']Thank you HansV[/quote]

    Hi HansV
    I was unable to get this to work for some reason. is it the ThisWorkbook.Path
    I have the userform on a word.docm that is located in same folder as Inspection Reports.

    Code:
    Set worddoc = wordapp.Documents.Open(ThisWorkbook.Path & "\Inspection Reports\Cover Page.docm")

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='ababenchrist' post='788358' date='10-Aug-2009 16:41']I was unable to get this to work for some reason.[/quote]
    Do you get a specific error message? If so, please say what it is.

    If you can use Debug when you get the error, choose Debug and mouse over ThisWorkbook.Path until the tooltip appears showing its value. Is it the value you expect?

  6. #6
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    [quote name='jscher2000' post='788361' date='10-Aug-2009 17:24']Do you get a specific error message? If so, please say what it is.

    If you can use Debug when you get the error, choose Debug and mouse over ThisWorkbook.Path until the tooltip appears showing its value. Is it the value you expect?[/quote]

    Hi jscher2000
    Yes I did
    Run time error '424' object required

    worddoc = Empty

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='ababenchrist' post='788362' date='10-Aug-2009 17:29']Run time error '424' object required[/quote]
    I wonder whether wordapp was not ready yet? It does take some time to fire up the Word application. If you run the macro, click Debug in the error dialog, then wait 60 seconds, then continue execution using F5, does it work? If so, that would point toward a timing problem.

    Actually, do you want to start a new instance of Word, or do you want to refer to the existing instance of Word? What is your code now (I was looking at your original post...)?

  8. #8
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='jscher2000' post='788365' date='10-Aug-2009 18:07']I wonder whether wordapp was not ready yet? It does take some time to fire up the Word application. If you run the macro, click Debug in the error dialog, then wait 60 seconds, then continue execution using F5, does it work? If so, that would point toward a timing problem.

    Actually, do you want to start a new instance of Word, or do you want to refer to the existing instance of Word? What is your code now (I was looking at your original post...)?[/quote]

    I tried waiting 60 seconds then continue execution using F5, no luck same error message.

    The code I use now is with a userform from excel. I'm trying to elilinate excel all together and just use Word, since most of my reports are a word.docm.
    this is the code I have been using and it still works great
    Code:
    Private Sub CommandButton1_Click()
    Set wordapp = CreateObject("Word.Application")
    Set worddoc = wordapp.Documents.Open(ThisWorkbook.Path & "\Inspection Reports\Cover Page.docm")
    	wordapp.Visible = True
    End Sub

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    ThisWorkbook is obviously Excel VBA. You can't use it from within Word. Try replacing it with ThisDocument.

  10. #10
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    [quote name='HansV' post='788374' date='10-Aug-2009 22:34']ThisWorkbook is obviously Excel VBA. You can't use it from within Word. Try replacing it with ThisDocument.[/quote]

    Hi HansV
    I double and triple checked both files are Microsoft Office 2007 Word Macro-Enabled Document. I thought just maybe one of the documents might be contaminated in some way, so I started a new document and added the code using the same method, with no such luck. I donít have a clue. I know you know your business, thatís why I'm so confused.

    As I ran the debug and then used my curser over highlighted area, this is what I got
    worddoc = Empty
    and on MyDocument.Path. the distination is correct

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can't use ThisWorkbook in Word. You must use ThisDocument or ActiveDocument instead.

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Oops, you edited your post while I posted my reply.

    What is MyDocument?

  13. #13
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='788430' date='11-Aug-2009 06:43']Oops, you edited your post while I posted my reply.

    What is MyDocument?[/quote]
    Hi HansV
    My oops this time I meant ThisDocument.Path

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    1. What is the code you're using now?
    2. Do you get an error message?
    If you do:
    2a. What is the error message?
    2b. On which line does the error occur?
    If you don't get an error message: what problem do you have?

  15. #15
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='788434' date='11-Aug-2009 06:58']1. What is the code you're using now?
    2. Do you get an error message?
    If you do:
    2a. What is the error message?
    2b. On which line does the error occur?
    If you don't get an error message: what problem do you have?[/quote]

    Hi HansV
    Here is the original code I used with my excel, No problems there
    Code:
    Private Sub CommandButton1_Click()
    Set wordapp = CreateObject("Word.Application")
    Set worddoc = wordapp.Documents.Open(ThisWorkbook.Path & "\Inspection Reports\Cover Page.docm")
    	wordapp.Visible = True
    End Sub
    Then I removed the
    Code:
    Set wordapp = CreateObject("Word.Application")
    and

    Code:
     wordapp.Visible = True
    As mentioned in your earlier comment
    So now it only leaves me with one line

    Code:
    Set worddoc = wordapp.Documents.Open(ThisWorkbook.Path & "\Inspection Reports\Cover
    Today I replaced ThisWorkbook with either ThisDocument or ActiveDocument
    Throughout this entire time I kept getting the same error message
    Run time error '424' object required
    then choosing debug I would put my mouse over

    Code:
    Set worddoc = wordapp
    A comment would appear

    worddoc = Empty

Page 1 of 3 123 LastLast

Posting Permissions

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