Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i change the filename of a word-file

Status
Not open for further replies.

Stefan29

Technical User
Oct 30, 2002
9
BE
I want to change the filename of a word-file without knowing the location where this file has to be saved to.
So the filename is known but the location has to be given later by the user. Is this possible in word?
 
Place this code into a standart module in your Word document:

Code:
Sub NewFileName_Word()
Application.Dialogs(wdDialogFileSaveAs).Show
End Sub

This will open the Save As... window. The file name will be in the "File name:" box, and your user only has to select the Folder path.



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
The "save As..." Window opens but the filename that Words propose isn't the correct filename. Can i change the filename Word propose in visual basic?
 
In that case, you will have to use this code instead:

Code:
Sub NewFileName_Word()
With Application.FileDialog(msoFileDialogSaveAs)
    .InitialFileName = "MyDocument.doc"
    .Show
End With
End Sub

Just change the "MyDocument.doc" to whatever you want!

Hope this helps!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Hi mike,

Thank you for your help. But now there is a error message that indicates that he doesn't recognise the method or property "Filedialog". I think that i have the insert a libary somehow but i haven't no idea with one and where i can have them! Can you help me?
 
I'm sorry Stefan,

I was using WordXP last night and didn't realize that the ".FileDialog" doesn't work with earlier versions. Here is the new code and It will work in Word 2000:

Code:
Sub NewFileName_Word()
With Application.Dialogs(wdDialogFileSaveAs)
    .Name = "MyDocument.doc"
    .Show
End With
End Sub

Sory again.

I really do hope this helps!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top