Consulting

Results 1 to 3 of 3

Thread: macro to display userform, insert data at bookmarks

  1. #1

    Question macro to display userform, insert data at bookmarks

    I'm on the struggle bus. This is my first macro. I haven't coded since I made my highschool sweetheart a website back in '02. I am trying to automate a legal document. Essentially, I want the end user to open the template and have it automatically bring up a userform that inserts the answers into the document at the bookmarks. I had it all good, except that it didn't autolaunch, but if I started the macro it would do what I wanted. I also tried to figure out a way to preserve the template and have it open a new document for the end user to save. I then managed to goober it all up. Now when I open the template, it opens a new document which has the text, but not the bookmarks. So the macro can't input the userform data at the bookmarks because they do not exist.

    I am a noob, so please pretend that I will have no idea what you're talking about unless you explain it like I've never coded before.

    Here is my beginner level code:
    This document:

    Sub AutoNew()
    UserForm1.Show
    End Sub

    Userform1:

    Private Sub CommandButton1_Click()


    Dim BM1 As Range
    Set BM1 = ActiveDocument.Bookmarks ("BM1").Range
    BM1.Text = Me.TextBox1.Value


    (there are 23 more of these)


    UserForm1.Hide
    Me.Repaint

    End Sub

    Help me... I have spent 10 hours trying to write automate a single template. Save me.

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    833
    Location
    Hi Anotherwayne and Welcome to this forum. I'm fairly sure that you want to ensure the "Template" document and the document generated by the "Template" both have the bookmarks already placed in the document. ie. the .dot, or dotx document, must have the bookmarks already placed in it when it is converted to a template doc. To create and then use templates, here's a link that looks like it might help. HTH. Dave
    Word Templates - Code - VBA (bettersolutions.com)

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,049
    Location
    As Dave has indicated, welcome to the VBAX forum Anotherwayne. We wrap our code with tags here to improve readability. To do so simply highlight your submitted code and click the # icon in the bar above when posting.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

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