Thread: [Solved] Generating a Letter
View Single Post
 
Old 09-29-2015, 09:18 AM
Shanna86 Shanna86 is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Sep 2015
Posts: 5
Shanna86 is on a distinguished road
Default

Slightly lost on how to name things. Currently my form has "var1" as the recipient's name

Quote:
Private Sub CommandButton1_Click()
'Define the variable oVars
Set oVars = ActiveDocument.Variables
'Hide the userform
Me.Hide
'Assign the values of the seven text boxes to the seven variables
oVars("var1").Value = Me.TextBox1.Value
oVars("var2").Value = Me.TextBox2.Value
oVars("var3").Value = Me.TextBox3.Value
oVars("var4").Value = Me.TextBox4.Value
oVars("var5").Value = Me.TextBox5.Value
oVars("var6").Value = Me.TextBox6.Value
oVars("var7").Value = Me.TextBox7.Value
'Update the fields in the body of the document
'Fields in other parts of the document will probably require extra code
'See http://www.gmayor.com/installing_macro.htm
ActiveDocument.Fields.Update
'Clear the variable
Set oVars = Nothing
'Unload the form
Unload Me
End Sub

EDIT: Sorry, hadn't reviewed the link you put in yet. I looked at the instructions for FillBM, just trying to figure out how to name it for the right value.
From what you have:

Quote:
Public Sub FillBM(strBMName As String, strValue As String)
'Graham Mayor
Dim oRng As Range
With ActiveDocument
On Error GoTo lbl_Exit
Set oRng = .Bookmarks(strBMName).Range
oRng.Text = strValue
oRng.Bookmarks.Add strBMName
End With
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
What part do I change to reflect the value from my textbox?

Last edited by Shanna86; 09-29-2015 at 09:23 AM. Reason: fixing
Reply With Quote