Discussion:
File Save As Dialog
(too old to reply)
Greg Mce
2003-12-08 06:05:42 UTC
Permalink
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
Jezebel
2003-12-08 06:44:54 UTC
Permalink
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.
Post by 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
pre
2003-12-08 10:05:35 UTC
Permalink
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.

--

pre
Post by 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
a***@discussions.microsoft.com
2003-12-09 00:47:59 UTC
Permalink
"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
-----Original Message-----
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.
--
pre
Post by Greg Mce
I have a form created in Word ' 97 that updates numerous
fields when the user presses an update button. At the
end
Post by Greg Mce
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
Post by Greg Mce
to save it with a new name. If yes then the File Save
as
Post by Greg Mce
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
Post by Greg Mce
no avail. I want the "file name already exists" message
box to appear. Your help will be most appreciated
Greg Mc
.
Kemosabe
2003-12-10 18:29:17 UTC
Permalink
On Mon, 8 Dec 2003 16:47:59 -0800,
Post by a***@discussions.microsoft.com
"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.
pre
2003-12-11 16:24:26 UTC
Permalink
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
--
pre
Post by Kemosabe
On Mon, 8 Dec 2003 16:47:59 -0800,
Post by a***@discussions.microsoft.com
"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.
Loading...