+ Reply to Thread
Results 1 to 6 of 6

how to reference already open word document

  1. #1
    Registered User
    Join Date
    11-04-2004
    Location
    Athens
    MS-Off Ver
    2019
    Posts
    48

    how to reference already open word document

    so i got some code in a workbook that opens a word document to use it as template to produce a mail body out of it.

    Please Login or Register  to view this content.
    This code works fine except in case that the required word document is already opened by the user. in this case i get command failed on the last line

    i tried adding error handling + the last line

    Please Login or Register  to view this content.
    where mailbodyTemplate is a file name like "myworddocument.docx"

    but in this case i get bad file name on the last line as wrdApp is empty of documents!

    seems that Set wrdApp even though it complains that the file is already open, does not contain the open file?

    any ideas how to get a referance to the already opened specific word document?

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,110

    Re: how to reference already open word document

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-04-2004
    Location
    Athens
    MS-Off Ver
    2019
    Posts
    48

    Re: how to reference already open word document

    thx for your reply!

    i adjusted the code a bit to also face a second problem but yea the core of what you provided was correct. it seems that every time the code did not complete i remained with open/hiden word instances and that also caused part of the problem. so now...

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: how to reference already open word document


    According to VBA help - a must read ! - you can directly use GetObject with the file full path-name rather than the application
    which links to the already opened document or if closed just opens it ...

  5. #5
    Registered User
    Join Date
    11-04-2004
    Location
    Athens
    MS-Off Ver
    2019
    Posts
    48

    Re: how to reference already open word document

    you are correct, but would i be able to readonly open this way?
    also, i would still need to know if wordapp and worddoc were already open or not so as to leave them in their prior state. if i do it automaticaly only with
    Please Login or Register  to view this content.
    how would i know?

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: how to reference already open word document


    I don't think so, according to VBA help ...

+ 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. Open word document in mac using VBA
    By bavarunbansal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2021, 09:44 AM
  2. Open up a blank word document when I open Excel
    By barneyrubble1965 in forum Excel General
    Replies: 5
    Last Post: 03-22-2018, 11:52 AM
  3. open excel source document in background when i open word document
    By hootiebsc in forum Word Programming / VBA / Macros
    Replies: 5
    Last Post: 03-22-2013, 07:50 PM
  4. Word browsing folder and open txt files in word document.
    By naseerrahaman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2013, 03:38 AM
  5. [SOLVED] Excel VBA to reference open word document
    By sharonb888 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2012, 01:08 AM
  6. Replies: 0
    Last Post: 06-07-2012, 02:21 PM
  7. Replies: 3
    Last Post: 05-13-2009, 11:51 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