Intercept XL info message with VBA 
Author Message
 Intercept XL info message with VBA

EXCEL 97

In VBA I save a template with the name specified by a user
(ActiveWorkbook.SaveAs name). When the user enters a name
already saved, XL responds with a message "A file named "name.xls"
already exists in this location. Do you want to replace it?" with options
Yes, No, Cancel.

Is there a way to intercept the user response of Yes, No, or Cancel or
must I use the Dir function in VBA to first check to see if a file exits
and if so respond to the user before the ActiveWorkbook.SaveAs name
is executed.

Bill Agee



Mon, 09 Jun 2003 07:12:56 GMT  
 Intercept XL info message with VBA
Just surround the command with

Application.DisplayAlerts = False
   ActiveWorkbook.SaveAs name
Application.DisplayAlerts = True

Regards,
Tom Ogilvy



Quote:
> EXCEL 97

> In VBA I save a template with the name specified by a user
> (ActiveWorkbook.SaveAs name). When the user enters a name
> already saved, XL responds with a message "A file named "name.xls"
> already exists in this location. Do you want to replace it?" with options
> Yes, No, Cancel.

> Is there a way to intercept the user response of Yes, No, or Cancel or
> must I use the Dir function in VBA to first check to see if a file exits
> and if so respond to the user before the ActiveWorkbook.SaveAs name
> is executed.

> Bill Agee




Mon, 09 Jun 2003 08:21:56 GMT  
 Intercept XL info message with VBA
Try

Function GetFileName()
    GetFileName = Application.GetOpenFilename("Excel Workbooks
(*.xls),*.xls,All Files (*.*),*.*")
End Function

Sub Test()
    Dim FileName As String
    FileName = GetFileName
    MsgBox FileName
End Sub

This uses the standard file open dialog within Excel but you control
explicitely what happens before and after the dialog is called.

Alternatively, you could use a call to a common dialog control embedded in
any user form but.. you get the windows standard browser rather than the
excel extended browser, if you intend to distribute your workbook you must
make sure all target platforms have the commdlg32.dll installed as it is not
installed by default.



Quote:
> EXCEL 97

> In VBA I save a template with the name specified by a user
> (ActiveWorkbook.SaveAs name). When the user enters a name
> already saved, XL responds with a message "A file named "name.xls"
> already exists in this location. Do you want to replace it?" with options
> Yes, No, Cancel.

> Is there a way to intercept the user response of Yes, No, or Cancel or
> must I use the Dir function in VBA to first check to see if a file exits
> and if so respond to the user before the ActiveWorkbook.SaveAs name
> is executed.

> Bill Agee




Mon, 09 Jun 2003 08:28:03 GMT  
 Intercept XL info message with VBA
Wouldn't  GetSaveAsFilename  be more appropriate here than GetOpenFilename.

Regards,
Tom Ogilvy


Quote:
> Try

> Function GetFileName()
>     GetFileName = Application.GetOpenFilename("Excel Workbooks
> (*.xls),*.xls,All Files (*.*),*.*")
> End Function

> Sub Test()
>     Dim FileName As String
>     FileName = GetFileName
>     MsgBox FileName
> End Sub



Mon, 09 Jun 2003 09:00:14 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Intercepting query error messages within a VBA procedure

2. VBA from XL Windows does not work in XL v.X

3. XL v5 sheets in XL 2000, vba translation problem

4. Intercepting Close event through AutoClose macro ( also intercepting FilePrint and FileSave)

5. Can VBA intercept keypress within Excel ?

6. How can i intercept a event in VBA?

7. Intercepting VBA Errors

8. Gradient & Intercept Excel VBA

9. Intercepting VBA errors

10. intercept of Word command line parameters in VBA


 
Powered by phpBB® Forum Software © phpBB Group