View Single Post
 
Old 08-24-2020, 02:01 PM
savvy savvy is offline Windows 10 Office 2016
Novice
 
Join Date: Aug 2020
Location: Toronto
Posts: 23
savvy is on a distinguished road
Default userForm input for filename

This is my UserForm:

Option Explicit

Private Sub CommandButton1_Click()
Dim PTFN As Range
Set PTFN = ActiveDocument.Bookmarks("PTFN").Range
PTFN.Text = Me.TextBox1.Value

Dim PTLN As Range
Set PTLN = ActiveDocument.Bookmarks("PTLN").Range
PTLN.Text = Me.TextBox2.Value

Dim DRFN As Range
Set DRFN = ActiveDocument.Bookmarks("DRFN").Range
DRFN.Text = Me.TextBox3.Value

Dim DRLN As Range
Set DRLN = ActiveDocument.Bookmarks("DRLN").Range
DRLN.Text = Me.TextBox4.Value
Me.Repaint
UserForm1.Hide



End Sub

Private Sub UserForm_Click()

End Sub


I would like to also have a macro which will place "PTLN, PTFN" into save as box in the proper folder. I tried just putting the text as the first line of the document but only the text of PTLN will be accepted and the ", text of PTFN" will not appear.

The document is a template.dotm which gets altered by several macros. The way I invoke save as is with F12.


I tried the below code but am too inexperienced to understand what the errors mean and how to fix them.
Sub SaveForm()
Dim strPath As String
Dim strName As String
strPath = Environ("USERPROFILE") & "\Documents"
' strName = ActiveDocument.FormFields("FieldName").Result
strName = ActiveDocument.Bookmarks("PTFN").Range


If strName = "" Then
MsgBox "Complete the 'fieldname' field!"
ActiveDocument.Bookmarks("PTFN").Select
Exit Sub
End If
With Dialogs(wdDialogFileSaveAs)
.Name = strPath & strName
.Show
End With
End Sub

Thanks
Reply With Quote