Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 9 Sep 2008 09:55:24 +0200,    group: microsoft.public.word.vba.userforms        back       


How to process string to word?   
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
date: Tue, 9 Sep 2008 09:55:24 +0200   author:   R.J. van Dam

Re: How to process string to word?   
"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
date: Tue, 9 Sep 2008 12:39:10 +0100   author:   Jonathan West

Re: How to process string to word?   
Tnx ... It works !!

RJ
date: Tue, 9 Sep 2008 16:28:47 +0200   author:   R.J. van Dam

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us