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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem manipulating File SaveAs dialogue box via VBA in word 2000

Status
Not open for further replies.

pastamark

Programmer
Jan 11, 2006
6
GB
Hello,

I was wondering if anyone has encountered the following problem when using automation through VBA to manipulate Word 2000 Dialog objects....

I am using automation to create a document in word that is based upon the data I have built up in word. Once I have created the document I would like to set the default file name of the doc so that when a user saves the document the correct name is shown in the File SaveAs dialog box.

I have found multiple references on the web to this code

Dialogs(wdDialogFileSaveAs).Name = PrefferedName

However when I attempt to do this in VBA (under access 2000) the .Name property is not exposed. The Microsoft Word 2000 object model states that this and a number of other properties should be exposed but they are not when I attempt to code it. Am I doing something wrong? Please help!
 
You have to use the Word.Application object:
[!]yourWordObject.[/!]Dialogs(wdDialogFileSaveAs).Name = PrefferedName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi,

Thanks for the reply, really appreciate it. Tried that and although VBA executed it it did not seem to do anything. Have found a solution that seems to work though...

With Dialogs(wdDialogFileSummaryInfo)
.Title = MyDocTitle
.Execute
End With

Once executed if I then attempt to save the doc the name I specify is shown.
 
You might instead try:
Code:
With Dialogs(wdDialogFileSummaryInfo)
        .Title = MyDocTitle
        .Show
End With
This will actually display the SaveAs dialog, with your default filename, but allow the user to change filename or path.


Regards,
Mike
 
Hello,

Thanks for the reply. I don't want to show the dialogue box to the customer automatically, I just want to set the File name correctly for when the user chooses to (hence the .Execute).

However having tried to set some proper titles using this method I seem to be having some problems in getting it to accept special characters. For example if I set the title of the doc to the following string

"T_CR_LIM DB2 table amendment 020206 153001.doc"

What I get is

"T"

Any ideas why and how I can get around this?
 
Hi pastamark,

I'm afraid you can't set a default save name in advance. Word will decide what to use based on what it finds in the Title or the document itself - and it will not use the underscore or anything after it.

If you want further control you will have to intercept the Save command/dialog when it is invoked. For that you will need code in the document (or its template) - you can't do it via automation.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Pastamark,

First, I managed to blindly use your code fragment without realizing you were calling a different dialog box. So here is what I meant to post:
Code:
With Dialogs(wdDialogFileSaveAs)
  .Name = DefaultFilename
  .Show
End With
Beyond that, I guess I don't actually understand what you are trying to achieve. Do you want to pre-set a default filename so when the user selects File|SaveAs the displayed dialog presents this default? If so, try:
Code:
[code]With Dialogs(wdDialogFileSaveAs)
  .Name = DefaultFilename
End With
Using the above with your filename string caused that to be displayed when I selected File|SaveAs.


Regards,
Mike
 
Mike,

You are right in that you can blindly execute the wdDialogFileSaveAs code. However when I do this it does not update the File name that appears if I do File SaveAs. I don't know the reason why this is not working but wdDialogFileSummaryInfo does seem to work and I am satisfied with the result of this except for the fact that any text I feed into the .Title property of this is truncated if I include special characters.

As the document I am generating in word is for DB2 table amendments, the table names I am defaulting in the SaveAs dialogue contains underscores e.g. T_CREDIT_LIMIT. So the default name simple ends up as "T".

Apparently this is a known problem with Word and have found some documentation with some form of work around at:

 
pastamark,

I see the deficiencies now. I have a new solution for you to try. Create the following procedure:
Code:
Sub FileSaveAs()
Dim DefaultFilename As String

  DefaultFilename = "T_CR_LIM  DB2 table amendment  020206 153001.doc"   '"MyNewFilename"
  With Dialogs(wdDialogFileSaveAs)
    .Name = DefaultFilename
    .Show
  End With
  
End Sub
The procedure name must be as given. When File|SaveAs is selected from the menu, this procedure will run instead of Word's built-in version. The custom procedure calls the built-in SaveAs dialog with the supplied default filename.


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top