In Word 2007, I created a Macro-Enabled Template that uses Form Fields with various calculations/formulas. I am trying to automate the .SaveAs based on the input of a text box from a UserForm with a command button click.
How do I dim and set the input text to use in the filename?
I have additional code to create an invoice number that I pull into the filename and that works. I'm just having problems with how to store the input text from the UserForm text box so that I can use in my AutoNew subroutine.
Sub AutoNew()
frmCustName.Show
Dim Cust As String
Dim RA as String
RA = ActiveDocument.Bookmarks("RntlAgrNO").Range.Text
Cust = txtInput
ActiveDocument.SaveAs FileName:="C:\MyPath\" & RA & Cust & ".docm"
End Sub
Here is my UserForm macro.
- My UserForm = "frmCustName"
- My TextBox = "txtInput"
- My CommandButton = "cmdName"
This populates the input text into two bookmarks in my form. How do I store this txtInput so that I can call it in my AutoNew code?
Private Sub cmdName_Click()
Dim BK As String
BK = txtInput
Dim NameBK1 As Range
Set NameBK1 = ActiveDocument.Bookmarks("CName1").Range
NameBK1.Text = BK
Dim NameBK2 As Range
Set NameBK2 = ActiveDocument.Bookmarks("CName2").Range
NameBK2.Text = BK
frmCustName.Hide
End Sub
Cust = ActiveDocument.Bookmarks("CName1").Range.Text