+ Reply to Thread
Results 1 to 18 of 18

Update document (Word file) on workbook open

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Update document (Word file) on workbook open

    Hello everyone
    Is there a way to update word document from cells in Sheets("INF") on workbook open
    I put example for word template

    In the third line the text "2015 / 2016"
    would be updated according to sheets("INF").range("B5')

    The same with the text "My Regards"
    Would be updated according to Sheets("INF").range("B3")
    Hope it is clear ..
    Thanks advanced
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Is it possible or would it be difficult to be done?

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Update document (Word file) on workbook open

    Hello YasserKhalil,

    Can you post an Excel workbook that has the data to be inserted into the Word document?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Thanks Mr. Leith for reply
    Here's normal file with the texts which I need to update the word document with
    Attached Files Attached Files

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Update document (Word file) on workbook open

    Hello Yasser,

    Is this "2015 / 2016" the only text for paragraph 3 or will it be inserted at the end of a line like in your example?

    Is the same true for "My Regards" ?

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Hello Mr. Leith
    sorry for late reply
    As for the word template is almost fixed in the structure
    I will attach again the two files (template document - excel file)
    All what I need is to run a macro in the excel file to change the underlined text in the word template ..
    As in the new attachment >>> the text "2014 / 2015" in the template would be the same value as in the excel file in Range("B5")
    the text "Thanks" in the template would be the same value as in the excel file in Range("B3")

    Hope it is clear now
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Any other questions Mr. Leith?

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Update document (Word file) on workbook open

    Hello Yasser,

    Here is the updated workbook. This will insert the data from the cells B3 and B5 of the worksheet INF into the specified Word document.

    Change the file path to where your Word document is saved.

    Module1 Macro Code
    Please Login or Register  to view this content.
    Workbook_Open Event Code
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Thanks a lot for this wonderful code
    I traced it using F8 and everything is ok but when opening the doc file I found results are not correct ...
    May be we can use different variables for Text variable?!

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Update document (Word file) on workbook open

    Hello Yasser,

    When you say "I found the results are not correct", do you mean the changes were not saved?

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Thanks I found the problem point
    It's this line

    Please Login or Register  to view this content.
    Should be
    Please Login or Register  to view this content.
    How can I replace specific word in the whole word document ...?

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Update document (Word file) on workbook open

    Hello Yasser,

    You can replace a word throughout the Word document using the Word Find method. If you need help with coding this, let me know.

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Yes I'm in the same context as I need to replace specific words ..say array of words with another array

    Old =Array("Testy","Yaser","Hallo")
    with the following array of words

    New=Array("Test","Yasser","Hello")

    Hope it is clear and simple

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Update document (Word file) on workbook open

    Hello Yasser,

    This should work.

    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Thank you very very much for all this great and awesome help
    Regards

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Update document (Word file) on workbook open

    Hello Yasser,

    You're welcome. Should I mark this post as solved?

  17. #17
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Update document (Word file) on workbook open

    FWIW, if you're always using the same Excel workbook and cells, you can do the lot without code. Simply copy the Excel cell, switch to the Word document and use Paste Special with the 'Paste Link' option and the paste format of your choice. If you need the same cell replicated in a number of places in the Word document, you could either:
    • replicate the link for each instance (e.g. by copying & pasting the first link to each subsequent location); or
    • bookmark the linked range then cross-reference the bookmark.
    The first option will update all references when the document is opened but will slow down the opening; the second option will update the first reference and the others will need the cross-references updated (e.g. via Ctrl-A, F9)
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Update document (Word file) on workbook open

    Thanks a lot Mr. Paul for this useful information
    Regards

+ 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. VBA to open a word document that is already linked in an Excel file for mail merge?
    By mshiddensecret in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-14-2015, 07:08 PM
  2. 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
  3. 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
  4. Replies: 0
    Last Post: 06-07-2012, 02:21 PM
  5. Update workbook without open XML source file
    By vietdieu in forum Excel General
    Replies: 0
    Last Post: 01-24-2012, 11:39 AM
  6. Open a Word document using cell value as the file name
    By cagmodels in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-01-2008, 11:10 AM
  7. Replies: 1
    Last Post: 10-17-2005, 04:05 AM

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