The following VBA Sub stops at the fourth Debug.Assert statement; but, will continue if I press F5 in the VBA editor. To my thinking, it should just continue because the expression "IsExcelWorkbook(sFilepath) = True" is true.
I've tried adding a Wait function and several DoEvents statements without any change in behavior.
When the code stops at the fourth Debug.Assert statement, the Test.xlsx workbook is open as expected. The VBA function IsExcelWorkbook(sFilepath) does return True after I click F5 or F8 in the IDE when execution conditionally stops waiting on the Debug.Assert. I've stepped through the code and it all works as expected; except that I hear a tone after clidking F8 on that fourth Debug.Assert statement. A second click on that statement allows execution to continue and "IsExcelWorkbook_test passed." shows up in the Immediate Window.
In the code below, the various procedures ReportStart, WaitAFewSeconds, ReportError, and ReportFinish do exactly what they imply and are functioning normally. The three Debug.Assert statements that precede the one commented as "Always stops here." also work as expected.
I'd appreciate any suggestions offered. Thanks for your time and consideration.
Bruce
I've tried adding a Wait function and several DoEvents statements without any change in behavior.
When the code stops at the fourth Debug.Assert statement, the Test.xlsx workbook is open as expected. The VBA function IsExcelWorkbook(sFilepath) does return True after I click F5 or F8 in the IDE when execution conditionally stops waiting on the Debug.Assert. I've stepped through the code and it all works as expected; except that I hear a tone after clidking F8 on that fourth Debug.Assert statement. A second click on that statement allows execution to continue and "IsExcelWorkbook_test passed." shows up in the Immediate Window.
In the code below, the various procedures ReportStart, WaitAFewSeconds, ReportError, and ReportFinish do exactly what they imply and are functioning normally. The three Debug.Assert statements that precede the one commented as "Always stops here." also work as expected.
I'd appreciate any suggestions offered. Thanks for your time and consideration.
Bruce
VBA Code:
Private Sub IsExcelWorkbook_test()
Const zsProcedure As String = "IsExcelWorkbook_test"
ReportStart zsProcedure, m_zsModule, m_zsLibrary, m_zbDebugging, m_zbLogging
#If LateBinding Then
Dim oXlApp As Object
#Else
Dim oXlApp As Excel.Application ' Requires a reference: Microsoft Excel xx.x Object Library
#End If
Dim sFilepath As String
Dim sTestResult As String
On Error GoTo ErrorHandler
sTestResult = zsProcedure & " failed."
sFilepath = "P:\TestFiles\Test.xlsx"
Debug.Assert IsExcelWorkbook(sFilepath) = False
DoEvents
Debug.Assert IsExcelWorkbook(sFilepath, OpenIfClosed:=False) = False
DoEvents
Debug.Assert IsExcelWorkbook(sFilepath, OpenIfClosed:=True) = True
' WaitAFewSeconds 10 ' Did not help.
DoEvents ' Did not help.
DoEvents ' Did not help.
DoEvents ' Did not help.
DoEvents ' Did not help.
DoEvents ' Did not help.
DoEvents ' Did not help.
Debug.Assert IsExcelWorkbook(sFilepath) = True ' Always stops here. F5 allows sub to complete without error.
DoEvents ' Did not help.
sTestResult = zsProcedure & " passed." ' After F5 this shows in the Immediate Window as expected.
Finally:
Debug.Print sTestResult
ReportFinish zsProcedure, m_zsModule, m_zsLibrary, m_zbDebugging, m_zbLogging
On Error GoTo 0
Exit Sub
ErrorHandler:
ReportError zsProcedure, m_zsModule, m_zsLibrary, m_zbDebugging, m_zbLogging
Select Case True
Case Else
If m_zbDebugging Then
'@Ignore StopKeyword
If m_zbEnableStops Then Stop
Continue
Else
' Silent return
Continue
End If
End Select
Resume Finally
End Sub