ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Nasty intermittent (https://www.excelbanter.com/excel-programming/416837-nasty-intermittent.html)

kirkm[_7_]

Nasty intermittent
 

VB code:

Dim frm As UserForm
For Each frm In UserForms
If frm Is frmLabel Then
If frmLabel.Visible Then Unload frmLabel
End If
Next


This works just fine 99% of the time. But ocassionally errror

frmlabel = <Object variable or With block variable not set

appears and the line highlighted is

If frm Is frmLabel Then

It's Ok on the next run though.

Anyone know what this might be?

Thanks - Kirk

NOPIK

Nasty intermittent
 
VBA has tiny stack for nested operators
try to complete condition with END IF to avoid recurcive stack
allocation.

Peter T

Nasty intermittent
 
this line -
If frm Is frmLabel Then
will Load frmLabel if it was not already loaded

If(?) the objective is to unload frmLabel if loaded (but not accidentally
load it merely by testing for it)

For I = UserForms.Count To 1 Step -1
If UserForms(i - 1).Name = "frmLabel" Then
Unload UserForms (i - 1)
' or
' Unload frmLabel
Exit For ' not necessary but might as well
End If
Next

Regards,
Peter T



"kirkm" wrote in message
...

VB code:

Dim frm As UserForm
For Each frm In UserForms
If frm Is frmLabel Then
If frmLabel.Visible Then Unload frmLabel
End If
Next


This works just fine 99% of the time. But ocassionally errror

frmlabel = <Object variable or With block variable not set

appears and the line highlighted is

If frm Is frmLabel Then

It's Ok on the next run though.

Anyone know what this might be?

Thanks - Kirk





All times are GMT +1. The time now is 03:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com