LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Using For/Next Loop To Generate 4 CommandButtons On A UserForm Results In A Runtime Error 91

Folkes,
My loop generates the buttons Ok but when I try and debug.print a
position property of the button I get :-
'Run-time error 91
Object Variable or with block variable not set'

I cannot see what is wrong but it must be something to do with the way
I am using Set and With within the loops. Can anybody point me in the
right direction.

Thanks for your help...again!

Here's my code:-

Option Explicit
Option Base 1
Sub delete()

Dim TempForm, Capn(), NewCommandButton() As Variant ' UserForm
Dim NewCommandButton1 As MSForms.CommandButton ' RC Variant
Dim NewCommandButton2 As MSForms.CommandButton ' RV Variant
Dim NewCommandButton3 As MSForms.CommandButton ' LC Variant
Dim NewCommandButton4 As MSForms.CommandButton ' LV Variant
Dim i As Integer, LeftPos As Integer

Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)

'Create and Postion the Variant Buttons
i = 1: Capn = Array("A", "B", "C", "D")
NewCommandButton = Array("NewCommandButton1", "NewCommandButton2",
"NewCommandButton3", "NewCommandButton4")
LeftPos = 15
For i = 1 To UBound(Capn)
Set NewCommandButton(i) =
TempForm.Designer.Controls.Add("forms.commandbutto n.1")
With NewCommandButton(i)
.Caption = Capn(i): .Top = 6: .Left = LeftPos: .Width = 25:
..Height = 17
End With
LeftPos = LeftPos + 30
Next i

Debug.Print NewCommandButton1.Left '********OK Until
Here**********
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
locking cells based on results at runtime aken Excel Worksheet Functions 3 June 22nd 05 02:01 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM
Add pictures to UserForm at runtime Dave[_33_] Excel Programming 1 December 6th 03 06:22 PM
add multiple checkboxes to userform at runtime gkelle Excel Programming 2 October 16th 03 04:16 PM


All times are GMT +1. The time now is 12:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"