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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
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
NorieAnalyst Assistant Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.