I am trying to automate a Word file with a userform.
I was thinking to have some variables in the Word file and to put a button in the ribbon that opens a userform to input these values.
I followed some tutorial I found online and I have the following code when I press OK on the userform:
Private Sub cmdOK_Click()
Set oVars = ActiveDocument.Variables
Hide
oVars(RfQ).Value = TextBox1.Value
oVars(SFDC).Value = TextBox2.Value
ActiveDocument.Fields.Update
Unload.Me
End Sub
I get the error
"Compile Error, Variable not defined".
In my text I have the following: {DOCVARIABLE SFDC * MERGEFORMAT}
My aim is to fill the variables with the value I input in the userform.
Further to this, I would like that every time I open the userform from the ribbon I get pre filled the information that is in the variable and that I can change/update them.