For Each loop causes code to stop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some code that is causing my code to stop until I move the mouse. What is weird is if I run it enough times the problem goes away but if I then close Inventor and reopen the problem comes back. It doesn't make any sense to me why moving my mouse would make it continue, but it does. Is there anyway I can re-write this better to make the problem go away? Thanks in advance.
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim ODoc As DrawingDocument
Set ODoc = oApp.ActiveDocument
Dim oSheet As DrawingViews
Set oSheet = ODoc.ActiveSheet.DrawingViews
Dim sheetsB As Sheets
Set sheetsB = ODoc.Sheets
Dim sheetB As Sheet
For Each sheetB In sheetsB 'rotates through each sheet
sheetB.Activate
sheetB.update
Dim oDrgViews As DrawingViews
Set oDrgViews = sheetB.DrawingViews
Dim oDrgView As DrawingView
Debug.Print "loop_start" & Time
For Each oDrgView In oDrgViews
Number = Number + 1
If Number = 1 Then
ViewHeight = oDrgView.Height
viewWidth = oDrgView.Width
End If
If Number = 2 Then
ViewLength = oDrgView.Width
End If
If Number = 4 Then
ViewHeightIso = oDrgView.Height
ViewWidthIso = oDrgView.Width
End If
Next
Next
Debug.Print "loop_end" & Time