Share via

docvariables and userforms

Anonymous
2011-07-19T04:27:43+00:00

Hello,

I am trying to create a template that allows information to be repeated through the document. My problem is that not all of the information is available when a document is created and I need to be able to keep going back to the userform to add/edit information.

I am having trouble with the code below:

Private Sub CommandButton1_Click()

Dim oVars As Word.Variables

ActiveDocument.Variables("v1").Value = TextBox1.Value

ActiveDocument.Fields.Update

Me.Hide

End Sub

Private Sub UserForm1_Initialize()

TextBox1.Value = ActiveDocument.Variables("v1").Value

End Sub

'macrobutton runs this macro to display the userform

Sub updater()

UserForm1.Show

End Sub

If I create a document and enter a value into textbox1, it all works fine. If I use my macrobutton to show the userform, the value of v1 is displayed in textbox1 which is exactly what I want. When I close and reopen the document, the value of the docvariable is maintained within the document but does not display in textbox1 on the form, can someone help me out with how I can do this?

Thanks in advance,

Mark

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

0 additional answers

Sort by: Most helpful