Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / March 2008

Tip: Looking for answers? Try searching our database.

Syntax problem with code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WLMPilot - 15 Mar 2008 20:05 GMT
Below is a macro I am testing.  I am trying to create 26 command buttons,
starting with Commandbutton6, but a caption starting with number 1.  
Something is wrong with the "Activesheet.OLEObject" line and I don't know
what.

Private Sub CommandButton2_Click()
Dim h, w, t, l As Long
Dim k As Integer
h = 21
w = 91.5
l = 50
t = 92
For k = 1 To 26
   ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton." & k + 5,
Left = l, Top = t, Width = w, Height = h)
   .Object.Caption = "Button " & k + 5
   t = t + 38
   If k = 7 Or k = 14 Or k = 20 Then
      l = l + 145
      t = 92
   End If
Next k
End Sub

Can someone tell me what is wrong?    Thanks

One other question.  I have seen the syntax similar to what I show below.  
If using this syntax, what is "newbutton" DIM as?

Set newbutton = Applicationsheet.OLEObject.Add(Forms.CommandButton....)

Thanks,
Les
WLMPilot - 15 Mar 2008 20:07 GMT
SORRY!.  I reposted in the Programming section.

Les

> Below is a macro I am testing.  I am trying to create 26 command buttons,
> starting with Commandbutton6, but a caption starting with number 1.  
[quoted text clipped - 29 lines]
> Thanks,
> Les
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.