I'm running the following sub and getting the 'Automation error
The object invoked has disconnected from its clients.' error at the bolded line. I've looked around, but don't see any help for this specific problem. Any help is appreciated.[vba]Option Explicit
Sub ShowMenu(ButtonName As String, ButtonLeft As Single, ButtonTop As Single, ButtonHeight As Single)
Dim img As MSForms.Image, lbl As MSForms.Label, frm As MSForms.Control
Dim fMenu As MSForms.Frame
Dim fillRange As Range
Dim L As Long
Dim maxWidth As Single
Set fMenu = UserForm1.Menu
Set fillRange = Sheet1.Rows(2).Find(ButtonName).Offset(2)
If fillRange.Offset(Rows.Count - 4, 1).End(xlUp).Row = 3 Then
L = 4
Else
L = fillRange.Offset(Rows.Count - 4, 1).End(xlUp).Row
End If
Set fillRange = fillRange.Resize(L - 3, 3)
With fMenu
.Left = ButtonLeft
.Top = ButtonTop + ButtonHeight
'Add menu items.
For L = 1 To fillRange.Rows.Count
Set frm = .Controls.Add("Forms.Frame.1", ButtonName & fillRange.Cells(L, 2))
With frm
.Caption = vbNullString
.SpecialEffect = fmSpecialEffectFlat
.Left = 0
.Top = L * 18 - 18
.Height = 18
Set img = .Controls.Add("Forms.Image.1", frm.Name & "Image")
With img
.Left = 0
.Width = 18
.Top = 0
.Height = 18
.BackColor = &H80000000
.BorderStyle = fmBorderStyleNone
.Picture = LoadPicture(fillRange.Cells(L, 1))
End With
Set lbl = .Controls.Add("Forms.Label.1", frm.Name & "Label")
With lbl
.Left = 24
.WordWrap = False
.Caption = fillRange.Cells(L, 2)
.AutoSize = True
If .Width > maxWidth Then maxWidth = .Width
.Top = 3
.Height = 12
.Accelerator = fillRange.Cells(L, 3)
End With
End With
Next
'Resize.
.Width = maxWidth + 3
For Each frm In .Controls
If TypeOf frm Is MSForms.Frame Then frm.Width = maxWidth + 1
Next
.Visible = True
End With
End Sub
[/vba]