A family of Microsoft word processing software products for creating web, email, and print documents.
If you get this set up correctly, the userform should be populated after closing and reopening the document. The reason is that document variables are saved in the document's file, and they're still defined when you reopen the document.
To your second question: Yes, you need to adapt the code to use the actual names of the document variables in your document. The code I showed was just an example, and it only tests the single document variable called "name" -- if you actually have one called "name".
For a real UserForm_Initialize() procedure, you could repeat the same kind of code for each of the variables, like
If DocVarExists("address") Then
docvarval = ActiveDocument.Variables("address").Value
Else
docvarval = ""
End If
If DocVarExists("phone") Then
docvarval = ActiveDocument.Variables("phone").Value
Else
docvarval = ""
End If
but that gets very tedious and hard to maintain. The next step is to write a function that takes the document variable's name as an argument and returns the value (or an empty string) to put into the userform's field:
Function GetDocVar(varName As String) As String
Dim docvarval As String
If DocVarExists(varName) Then
docvarval = ActiveDocument.Variables(varName).Value
Else
docvarval = ""
End If
GetDocVar = docvarval
End Function
(This is in addition to the DocVarExists function you already have.) Then the Userform_Initialize procedure can just be a series of lines like this, one for each document variable / userform field combination in your document:
Private Sub UserForm_Initialize()
txtAddress.Text = GetDocVar("address")
txtPhone.Text = GetDocVar("phone")
' etc. ...
End Sub