+ Reply to Thread
Results 1 to 8 of 8

Creating and Editing Word Doc from within Excel; Procedure Randomly Stops

  1. #1
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208

    Creating and Editing Word Doc from within Excel; Procedure Randomly Stops

    Hi everyone. I hope I can get some insight here.

    Using Office 97/Win 2k Pro and Office 2003/Win XP Pro, same results.

    I have a workbook that creates a Word document using a command button and userform. The command button calls the user form, data is entered by the user, and when a command button on the user form is clicked, the document is generated.

    Sometimes, I can step through the procedure, and it will work all the way through. Sometimes, it seems as if I step through too fast, the procedure seems to just stop without warning, and will not go any further. If I try to run the procedure by simply clicking the command button, it will never run all the way through.

    The procedure that is generating the Word document is as follows:
    Please Login or Register  to view this content.
    Thanks in advance for any input.

    Jason

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Jason

    Tried some parts of this and managed to get so far. Created a couple of temp documents (xxx.doc and xxxx.dot) on C:\temp to give it something to work with and it only bombed out when it came to finding some of the items on the document.

    Can you put up a sample of the word doc and template (nothing sensitive) that we can use to work with. Gets a bit difficult trying to replicate all your items....


    rylo

  3. #3
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Thanks for the reply, Rylo. I will post up the files when I return to work on Monday.

    Jason

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Ok, here are the files. On the 2008 Log.xls file (password is "password"), I changed the name of the files in the code to refer to:

    C:\Temp\DM.doc

    and

    C:\Temp\LH.dot

    DM.doc is the letter that is opened and modified. LH.dot is our company's letterhead that is opened, header copied, and closed. Please save both of these to C:\Temp to properly work.

    The code to open and edit the Word document is in Module2. I did make several changes to the Excel and Word files, since some of the information was proprietary, but it should still work as intended.

    If it works for you the first time, please close Word and try it again. Every once in a while it will work for me just fine. But if I try it again, it will not work properly. I moved the visibility and activation of the Word app to the beginning of the procedure, in order to help see the stopping point of the code.

    Again, I really appreciate any help on this issue.

    Jason
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Jason

    I didn't have trouble with this until it tried to do the find. I'm not much for word macros, but couldn't find the syntax in Excel to do the find in word. Could do a word macro, but not in excel.

    There was also the problem that "UB (" didn't seem to exist.

    Can you get the excel code to do a find in word, then select the text???

    rylo

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Hi, rylo.

    Yeah, you can delete the few lines of code that try to find that text string. I deleted that when I was editing the file to be posted. Sorry about that.

    As for using Excel to search in Word, I'm not sure how to do that... I created that code basically by recording a macro in Word, then copying and pasting after I got it to where it needed to be.

    Any other ideas?

    TIA

    Jason

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Jason

    Here's a part of the puzzle. I got this to work for the find replace parts.

    OLD

    Please Login or Register  to view this content.

    NEW

    Please Login or Register  to view this content.
    All I did was comment out the old, and inserted the new and it seemed to do the replace. However, still haven't found the syntax for the earlier find operations...


    rylo

  8. #8
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Ok, I changed all of my Find statements, but that didn't seem to help. It still bombs out sometimes during the initial page setup of wrdDoc.

    I am going to post a thread on another forum, since this may be more of a Word issue:

    http://www.vbaexpress.com/forum/showthread.php?t=15722
    Last edited by jasoncw; 10-24-2007 at 05:14 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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