Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Userform to add text to Word 2010 doc then print then start all over

    Hello All,

    I'm new to this forum but have found many answers here to many of my other problems. I'm hoping someone could help me. What I'm trying to do is take a Word 2010 template with bookmarks and utilizing a Userform, open a doc based on the template and collect the data needed to populate the bookmarks, then when submitting the userform, print the doc, then start all over without saving the initial doc. It seems I can't get this working correctly and could ue some help.

    I have the template built and the userform built along with the submit button and it populates the bookmarks on the doc. I then am able to print the doc with a command button Print on the doc. The next button on the doc is NEW LETTER but I can't get a new iteration of this going. I think there is something preventing it from the template stand-point - not sure. Here is my NEW LETTER code:


    Sub CommandButtonNewLetter_Click()
    ActiveDocument.Close (Word.WdSaveOptions.wdDoNotSaveChanges)
    Documents.Add Template:=Options.DefaultFilePath(wdUserTemplatesP ath) & "\Letter.dotm"
    End Sub


    What happens is the active document does close without a save, but I then get a blank screen. It doesn't seem to want to open a new round so I can create the next letter.

    What I just learned is if I use the Templates add-Ins and point to the template then check the box, it works as it supposed to. But if you close Word the checkbox in Templates Add-Ins goes unchecked and now it won't work. I would have to check this box every time I would start a new session of Word. Is there a way to make this checkbox checked perminently?

    Now I learned that this checkbox will always go unchecked when Word is restarted. What others are recommending is to place my template in the starup folder and I tried that but I can't get the new iteration to start. It just closes the first iteration and does not start the second iteration.

    So as I continued to research this issue I finally figured out what was happening. It all has to do with using a template and ensuring it's in the startup and the NEW LETTER button points to the startup folder. Now all works.


    Any help would be much appreciated.


    Thanks - Tom
    Last edited by tommygun; 2013-01-26 at 21:04.

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Where is your macro stored? If it is in the document that you are closing then how do you expect the macro to be able to run once the file is no longer open.

    Since you are only changing the content in the bookmarks locations then why do you need to close the document at all? Can't you just retain the same userform and change the contents of the file at the same bookmark locations.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes this is true and a good idea but I just couldn't figure out how to remove the data placed in the word doc immediately after the bookmarks. If I can figure that out then I wouldn't have to close the doc and start all over.

    If someone could advise how to clear the bookmark data in the word doc then that would be much appreciated.

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Have a look at this function provided by Gary Frieder. It allows you to put the text inside the bookmark so you can easily find and replace it later
    http://windowssecrets.com/forums/sho...ll=1#post95679

    There are other options to do this sort of thing - if you still can't work it out, let me know.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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