PC Review


Reply
Thread Tools Rate Thread

Command Button coding

 
 
Corey
Guest
Posts: n/a
 
      23rd Nov 2006
In my quest for the ultimate project goal, i am now trying to place a comman
button on a new sheet.
I can get the code below to place it on the sheet, but when i recorded the
code in did not record the Button Title, nor the sheets("Leave
Blank").select step.

Is there a way i can code this into the below code to create the button?

ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=264.75, Top:=516.75, Width:=119.25, _
Height:=22.5).Select

Want the button to be Captioned "EXIT"
and
the clicking of it to selecting sheet named "Leave Blank".

Corey....


 
Reply With Quote
 
 
 
 
wisccal@googlemail.com
Guest
Posts: n/a
 
      23rd Nov 2006
Hey Corey,

There are a number of posts that have good examples to solve this
problem (search terms: "programmatically add controls to worksheet").
You want to do something like:

'===========================
Dim ws As Worksheet, oleObj As Excel.OLEObject

Set ws = Sheets(1)

Set oleObj = ws.OLEObjects("CommandButton1")
oleObj.Object.Caption = "EXIT"
With ThisWorkbook.VBProject.vbComponents(ws.CodeName).CodeModule
.InsertLines .CreateEventProc("Click", oleObj.Name) +1, _
vbTab & "ThisWorkbook.Sheets(" & Chr(34) & "Leave Blank" &
Chr(34) & ").Select"
End With
'===========================

Regards,
Steve

Corey schrieb:

> In my quest for the ultimate project goal, i am now trying to place a comman
> button on a new sheet.
> I can get the code below to place it on the sheet, but when i recorded the
> code in did not record the Button Title, nor the sheets("Leave
> Blank").select step.
>
> Is there a way i can code this into the below code to create the button?
>
> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
> , DisplayAsIcon:=False, Left:=264.75, Top:=516.75, Width:=119.25, _
> Height:=22.5).Select
>
> Want the button to be Captioned "EXIT"
> and
> the clicking of it to selecting sheet named "Leave Blank".
>
> Corey....


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with coding a command button. dan dungan Microsoft Excel Programming 2 27th Apr 2009 07:53 PM
coding a command button Chuck216 Microsoft Access 4 31st Jul 2008 09:01 PM
command button coding..... seema Microsoft Access Getting Started 5 30th Jan 2008 08:44 PM
Command Button VB Coding =?Utf-8?B?U3VlIFdpbGtlcw==?= Microsoft Access Getting Started 4 27th Nov 2006 12:56 PM
Command Button Coding question Rich S. Microsoft Access Form Coding 1 8th Jul 2003 05:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 PM.