Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Apr 2003
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Userforms in Word (Office2000)

    I am trying to create a user form in a word document that will transfer text from the textboxs in the user form and display them in the word document. I am familiar with writing code for excel, using ranges. Im not sure how to achieve the same results in word.
    Thanks in advance.

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userforms in Word (Office2000)

    The text values in the textboxes of the userform can be transferred to the MS Word document easily via bookmarks. For instance, if you want the Word doc to look like a completed userform for printing purposes, then design a table with bookmark placeholders. Then when the user finishes with the userform and clicks the OK command button, it will pass the contents to the relevant bokmarks in the document.

    The following is a part of code I used in a FAX coversheet.

    <pre>Private Sub cmdOK_Click()
    Dim T As String, SH As String, F As String, _
    DB As String, P As String, F2 As String, _
    F3 As String, F4 As String, F5 As String


    T = txtTo.Text
    SH = txtToOrg.Text
    F = txtFrom.Text
    DB = txtFromLocation.Text
    P = txtFromPhone.Text
    F2 = txtFromFax.Text
    F3 = txtToFax.Text
    F4 = txtToPhone.Text
    F5 = txtNoPages.Text

    ActiveDocument.Bookmarks("ToPerson").Select
    Selection.TypeText Text:=""
    Selection.Text = T

    ActiveDocument.Bookmarks("ToOrg").Select
    Selection.TypeText Text:=""
    Selection.Text = SH... etc.</pre>



    I hope this helps.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Userforms in Word (Office2000)

    There are several possibilities. The zipped template attached to <post#=259183>post 259183</post#> demonstrates one of them: store the values from the text boxes in document variables, and use DOCVARIABLE fields in the document to refer to those variables. (You may want to take a look at the rest of that thread for more info about this method.)

    If you want to "type text" directly into the document using code, look up the TypeText and TypeParagraph methods of the Selection object, and/or the InsertBefore and InsertAfter methods of the Range object in the online help.

  4. #4
    New Lounger
    Join Date
    Apr 2003
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userforms in Word (Office2000)

    Thanks for that LeighW, works a charm.

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Userforms in Word (Office2000)

    You have several potential methods of doing this
    - use bookmarks to mark the locations
    - search and replace
    - put form data into document properties and use fields in the document to update this

    The bookmarks method is good if you have only one location for each item from the form. This is because you can't have two bookmarks with the same name.

    If you do a search on this forum (and in VBA) you will find several instances of code to get you going.
    <post#=330850>post 330850</post#> and <post#=332112>post 332112</post#> from the same thread show two of these options.

    I note that Kerry couldn't get my code working when she tried so perhaps the first option is less problematic.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Userforms in Word (Office2000)

    Whoa - this question got some answers fast.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Userforms in Word (Office2000)

    Now Dembo has a wealth of different options to choose from, although it seems the first reply already does it.

Posting Permissions

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