Formulario VBA en Macros de Word. ¿Insertar dato de textbox en otro macro?

Tengo una macro en WORD, que crea una especie de serial en el encabezado del documento, y he creado un Formulario de VBA que al abrir el documento me pida mi DNI para luego insertarlo como parte del serial del documento de word.

En el macro de abajo hay una referencia (Const sText As String =" Legajo No.") que hace que el Macro inserte el numero de serie con ese prefijo, pero necesito que luego de la palabra LEGAJO N° se inserte el numero de documento que ingrese en el texbox del formulario al abrir word.

El Macro que crea el serial es el siguiente (lo encontré en otra pagina)

Option Explicit
Private CertNo As String
Private oHeader As Range
Private oHead As HeaderFooter
Private oField As Field
Private sName As String, sPath As String
Private oVars As Variables
Private bProtected As Boolean
Const sFormat As String = "000#"
Const sText As String =" Legajo No."
Const sPassword As String = "emi" 'The password to edit the form

Sub AutoNew() 'Add a number when a new document is created
'If the document is a protected form, unprotect it
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=sPassword
End If
sPath = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"
Set oVars = ActiveDocument.Variables
CertNo = System.PrivateProfileString(sPath, "MacroSettings", "CertificateNumber")
If CertNo = "" Then 'The settings file entry does not exist
CertNo = 1 'So set the start number
Else 'The settings file entry does exist so increment it by 1
CertNo = CertNo + 1
End If
'Define two document variables of the same initial value
oVars("varCertNo").Value = CertNo
oVars("varSaveNo").Value = CertNo
'The number is to be placed in the header on the first page
'so establish which type of header that is.
If ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Exists Then
Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
Else
Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
End If
'Setup the format of the header.
'Note that this will remove any existing header content
'So ensure you include anything else required in the header
'Here we have some fixed text, and assorted formatting that should
'be self evident.
With oHeader
.Text = sText
.Font.Name = "Arial"
.Font.Bold = False
.Font.Italic = True
.Font.Size = "12"
.ParagraphFormat.Alignment = wdAlignParagraphRight
.Collapse wdCollapseEnd
'Insert a docvariable field to display the formatted number
.Fields.Add oHeader, wdFieldDocVariable, """varCertNo"" \# " & sFormat, False
.Fields.Update
End With
'Save the number in the INI file
System.PrivateProfileString(sPath, "MacroSettings", "CertificateNumber") = CertNo
'If the document was unprotected initially,
' reprotect the document for forms.
If bProtected = True Then
'ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPassword
Selection.Editors.Add wdEditorEveryone
ActiveDocument.Protect Password:=sPassword, NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
End If
End Sub

Espero alguien me pueda ayudar ya que estoy trabadisimo en este momento..

Saludos y gracias.

Añade tu respuesta

Haz clic para o