Avatar of Hamza Bazger
Hamza Bazger

asked on 

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
ProgrammingVBAMicrosoft Word

Avatar of undefined
Last Comment
Hamza Bazger
Avatar of Norie
Norie

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

Avatar of Hamza Bazger
Hamza Bazger

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Hamza Bazger
Hamza Bazger

ASKER

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
Avatar of Hamza Bazger
Hamza Bazger

ASKER

I just needed the code to be edit and NORI the GOD of VBA did it.!
Programming
Programming

Programming includes both the specifics of the language you’re using, like Visual Basic, .NET, Java and others, but also the best practices in user experience and interfaces and the management of projects, version control and development. Other programming topics are related to web and cloud development and system and hardware programming.

55K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo