File Save As Dialog

G

Greg Mce

I have a form created in Word ' 97 that updates numerous
fields when the user presses an update button. At the end
of the updates a message box asks if the user wants to
save the form and if they do then are asked if they want
to save it with a new name. If yes then the File Save as
dialog box is called using this code.
x = Dialogs(wdDialogFileSaveAs).Show

My question/problem is that if the user selects the same
file name as an existing one at this point absolutely
nothing happens. I would have thought the "File Name
already Exists" message box would appear. If a diferent
file name is entered it saves without a problem.

I have tried removing the Application.DisplayAlerts =
wdAlertsNone code, setting it to "wdAlertsAll" but all to
no avail. I want the "file name already exists" message
box to appear. Your help will be most appreciated

Greg Mc
 
J

Jezebel

Instead of using the Word dialog, you could add a commondialog control to
your form and use that to get the file name. The dialog provides an
automatic 'prompt to overwrite' message.
 
P

pre

Maybe there´s som inspiration in this:

Dim FilesystemObj As New Scripting.FilesystemObject

Dim sFileName As String

sFilename = ActiveDocument.FullName

aFilename = Left(ActiveDocument.FullName,
Len(ActiveDocument.FullName) - 4)

If FilesystemObj.fileexists(sFilename) Then

x = MsgBox(sFileName & vbCr & "Add a Number Y/N", vbOKCancel)

End If

If x = vbOK Then

sFilename = aFilename & "1" & Right(sFilename, 4)

End If

ActiveDocument.SaveAs FileName:=sFilename



NB: A Reference set to Microsoft Scripting Runtime is necessary.
 
G

Guest

"pre"

I used and adapted the code as per below. The first time
you press the save button it still does nothing. It seems
like the save button is not getting trapped at all.

If you press Cancel and using the prompts I have it
reloads the SaveAs dialog. This time if you press save
with an existing file name it first saves the form with
that name and then runs the code below perfectly.

I am unable to load the CommonDialog control as it gives
me a nice message that I am not licenced.

Any clues on this rather bizarre behaviour

Greg Mc
 
K

Kemosabe

"pre"

I used and adapted the code as per below. The first time
you press the save button it still does nothing. It seems
like the save button is not getting trapped at all.

If you press Cancel and using the prompts I have it
reloads the SaveAs dialog. This time if you press save
with an existing file name it first saves the form with
that name and then runs the code below perfectly.

I am unable to load the CommonDialog control as it gives
me a nice message that I am not licenced.

You can create a common dialog using API. See
http://www.mvps.org/vbnet/ or http://www.vbaccelerator.com/

There are other examples out there also.
 
P

pre

As noted the code was intended as a source for inspiration. However its
working fine here (On trial, intended for use in an event system)

The reference to the Microsoft Scripting Runtime is a must
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top