Hi In de userform I have several optionboxes representing some persons. Depending wicht optionbox selected I want to assign a name and a phonenumber to a variable. How do I get those variables to word? Defined in word the fields with { DocVariable "strName" \* MERGEFORMAT } and {DocVariable "strPhone" \* MERGEFORMAT } I'm using Word2007. My code: Private Sub CommandButton1_Click() Dim strName As String Dim strPhone As String If OptionButton1 Then strName = "Joe" strPhone = "555-4897" ElseIf OptionButton2 Then strName = "Sarah" strPhonel = "555-5678" End If 'How to process strName and strPhone to Word to replace { DocVariable "strName" \* MERGEFORMAT } and {DocVariable "strPhone" \* MERGEFORMAT }? UserForm1.Hide End Sub Regards, RJ
"R.J. van Dam" wrote in message news:56575EB1-C917-4C4C-B532-546527B0059D@microsoft.com... > Hi > > In de userform I have several optionboxes representing some persons. > Depending wicht optionbox selected I want to assign a name and a > phonenumber to a variable. How do I get those variables to word? Defined > in word the fields with { DocVariable "strName" \* MERGEFORMAT } and > {DocVariable "strPhone" \* MERGEFORMAT } > I'm using Word2007. My code: > > Private Sub CommandButton1_Click() > > Dim strName As String > Dim strPhone As String > > If OptionButton1 Then > strName = "Joe" > strPhone = "555-4897" > ElseIf OptionButton2 Then > strName = "Sarah" > strPhonel = "555-5678" > End If > 'How to process strName and strPhone to Word to replace { DocVariable > "strName" \* MERGEFORMAT } and {DocVariable "strPhone" \* MERGEFORMAT }? > UserForm1.Hide > End Sub Hi RJ You need to distinguish between variables (as used in programming langauges) and Document Variables, which are for invisible data included in the document. Assuming you leave the DOCVARIABLE fields as they are, you need to change your code as follows If OptionButton1 Then ActiveDocument.Variables("strName") = "Joe" ActiveDocument.Variables("strPhone") = "555-4897" ElseIf OptionButton2 Then ActiveDocument.Variables("strName") = "Sarah" ActiveDocument.Variables("strPhone") = "555-5678" End If ActiveDocument.Range.Fields.Update The last line of code is intended to make sure that the DOCVARIABLE fields pick up the new values you have just written to the variables themselves. -- Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup
Tnx ... It works !! RJ