Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    UK, Surrey
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting text with a form and putting it into Word Documents Word 2007

    How can I prompt a user for information, do a few tweaks do it, save some text strings, and have the text strings appear where I want them to in a Word 2007 document?

    I have to prepare some standard letters. They need to collect some information (addressee's name, reference number..., which of three choices...). I've set up a form to prompt the user for these data. I then have it run some If Then conditions and set some text strings. I then want the text strings to go into the document...

    This is where I'm stuck. I hoped that "DocVariable" field could use the text string I'd saved in the form to enter the text string. No luck.

    I thought that if I used e.g.

    'Add bookmark text for sender's name
    expression.Add (BkmTxt_SendersName)
    BkmTxt_SendersName = str_SendersName

    I could then use the cross-reference functions (cross reference, bookmark, insert bookmark text) e.g. {REF BkmTxt_SendersName \h} in the document but it gives an error message ("Error! Reference source not found,").

  2. #2
    Star Lounger
    Join Date
    Jan 2001
    Location
    UK, Surrey
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Another approach... Document Custom Properties
    I can edit the template to include custom properties. (Office button aka File|prEpare|Properties, document properties dropdown menu, Advanced Properties, Custom tab, type in the new custom property's name and a default value...

    I could, for example, create a custom property "SendersName".

    I can then use the DOCPROPERTY field: {DOCPROPERTY SenderName \* MERGEFORMAT}.

    Then I could get the VBA code in the form to set the property to the value of the string str_SendersName. Then all I need to do is to select the document and update all fields..

    So I now need to work out how to set the DOCPROPERTY to the new value, based on the form input. Assuming I've succeeded in setting str_SendersName to e.g. "Dr Peter English" I think I need something like:

    With CustomDocumentProperties
    .Add Name = "SendersName", Type:=String, Value:=str_SendersName, LinktoContent:=False
    End With

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    penglish,

    Here's a Word Template that does what I think you're after. Give it a look. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    UK, Surrey
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope. "Invalid procedure call or argument".

  5. #5
    Star Lounger
    Join Date
    Jan 2001
    Location
    UK, Surrey
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow - what a lot of data is collected in those forms! Thank you so much, though - I think I can see the syntax I need now.

    So, if the text box in my form is called Box_SenderName, I can use:

    With ActiveDocument
    .Variables("SenderName").Value = Trim(Box_SenderName.Value)
    End With

    to get the content of the form's text box into a custom document variable called Sendername...

    Presumably

    With ActiveDocument
    .Variables("SenderName").Value = str_SenderName
    End With

    will also work.

    I'll try that tomorrow!

    Thank you very much!

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
  •