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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Getting text with a form and putting it into Word Documents Word 2007

    Author
    Topic
    #487855

    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,”).

    Viewing 2 reply threads
    Author
    Replies
    • #1375454

      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

    • #1375456

      penglish,

      Here’s a Word Template that does what I think you’re after. Give it a look. HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #1375471

        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!

    • #1375460

      Nope. “Invalid procedure call or argument”.

    Viewing 2 reply threads
    Reply To: Getting text with a form and putting it into Word Documents Word 2007

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: