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

VBScript focus on Excel Alert

Status
Not open for further replies.

jimbolove

Instructor
Jun 26, 2006
8
US
My code is using errorcodes generated from Excel. So I don't want to turn off alerts. However I'm having an issue and want to answer the Excel Alert caused by the save error "File already exists, Do you want to save over?" message and want to answer "No". Is this possible? Below is some of my code:
Set oExcelFile = oFileObject.GetFile(strExternalFilePath)
strExcelFileName = oExcelFile.Name
Set oExcelObject = GetObject("","Excel.Application")
Set ExcelWorkbook = oExcelObject.Workbooks.Open(strExternalFilePath)
Set oExcelSheet = ExcelWorkbook.Sheets(1)

On Error resume next
oExcelSheet.parent.save
If Err.Number <> 0 Then
OExcelObject.diplayalerts.Visible = True
msgbox "The file is open and needs to be closed"
subDestroyObjects
wscript.quit
Else

oExcelObject.Application.Windows(strExcelFileName).Visible = True
oExcelObject.Application.Visible = False
End If

End IF
End Sub
 
Hi,

OExcelObject IS the Excel Application Object. Look at your Set statement.

OExcelObject.DisplayAlerts = FALSE

...turns off alerts.
 
Skip thanks for the response but if I turn off alerts then I don't get the error code. The script just continues to run. Whereas I don't want the script to continue if there is an error.
 
Then why can't you answer the alert? Is the Excel Application visible at that instant?
 
I can't seem to activate the box, it's visible but it's not letting me focus on it.
 
You might try this...

Code:
On Error resume next
oExcelSheet.parent.save 
If Err.Number <> 0 Then

   MsgBox err.message, vbYesNo

   If vbYesNo = "Yes" Then

   Else

   End If

Else

End If

On Error Goto 0.  'Turn off on error.
Code the yes /no according to your needs.
 
Here's the alert box that I'm getting from excel, but nothing I try seems to focus on it.
 
 http://files.engineering.com/getfile.aspx?folder=13e9e39b-ed65-4ad7-b438-c2daa53c1ca0&file=Capture.JPG
Oh, I should have added to first set DisplayAlerts to FALSE, then the code I posted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top