How to Save as what entered in TextBox1

Greetings!

I am very new to VBA. Please be forgive me if I don't follow the programming rules. It is not because I am rude, it is because I don't know.

I have a Word Document template that data is entered in the UserForm TextBoxe1.
I want a code that saves the Document as the value entered in the TextBox1.

Here is my main program with other irrelevant codes that I left out...

Private Sub CommandButton1_Click()
       Dim LFname As Range                                                                               ' LFname is a bookmark in the document
              Set LFname = ActiveDocument.Bookmarks("LFname").Range
             LFname.Text = Me.TextBox1.Value                                                     ' TextBox1 is the TextBox in the UserForm where Last name and First name is entered .


And here is the save sub.          
             
Private Sub CommandButton2_Click()

    Set dlgSaveAs = Dialogs(wdDialogFileSaveAs)
    With dlgSaveAs
        .Name = "????????? "                                                   ' This is where I want the Last name and First name entered in the TextBox1 to appear
        .Format = wdFormatXMLDocument
        .Show
    End With

Thanks in advance
 

End Sub
Hamza BazgerAsked:
Who is Participating?
 
NorieConnect With a Mentor VBA ExpertCommented:
It works for me.

I entered 'TestDocName' in TextBox1, clicked CommandButton2, the dialog opens with 'TestDocName.docx' in the name box and when I click Save a file with that name is saved to the current directory.
0
 
NorieVBA ExpertCommented:
Perhaps this is all you need.
Private Sub CommandButton2_Click()

    Set dlgSaveAs = Dialogs(wdDialogFileSaveAs)

    With dlgSaveAs
        .Name =TextBox1.Value & ".docx"
        .Format = wdFormatXMLDocument
        .Show
    End With

    
End Sub

Open in new window

0
 
Hamza BazgerAuthor Commented:
I am thrilled with the quick response from Nori! Thank you very much.

But,

However this does not appear to work. I get a blank area for File Name.
I don't know what I am doing wrong.  
I entered a name in the TextBox1 and after clicking save command button the program does opens the save as dialog box but there is no name to be saved as.
please help Thank you
0
 
Hamza BazgerAuthor Commented:
IT WORKED .....!

I don't know what I was doing wrong. I give up and did not bother with it.
but today I give it another try and My GOD I am glad I did...I thought it will never will work. NORI you are the God of VBA
Thank You So Much
0
 
Hamza BazgerAuthor Commented:
I just needed the code to be edit and NORI the GOD of VBA did it.!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.