PC Review


Reply
Thread Tools Rate Thread

Create Control Button

 
 
=?Utf-8?B?TGFycnk=?=
Guest
Posts: n/a
 
      2nd Oct 2006
Playing arround with this routine, It does everything expected by creating
the button, but when it finnishes it stays in the code module. Is there
anyway after the routine finnishes that it can revert back to the worksheet.
The code is as follows:

'-----------------------------------------------------------------
Sub CreateControlButton()
'-----------------------------------------------------------------
Dim oWs As Worksheet
Dim oOLE As OLEObject

Set oWs = ActiveSheet

Set oOLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Left:=200, Top:=100, Width:=80, Height:=32)

'To set with a cell
'With Range("H2")
' Set oOLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
' Left:=.Left, Top:=.Top, Width:=.Width,
Height:=.Height)
'End With

With oOLE
.Object.Caption = "Run myMacro"
.Name = "myMacro"
End With

With ThisWorkbook.VBProject.VBComponents(oWs.CodeName).CodeModule
.InsertLines .CreateEventProc("Click", oOLE.Name) + 1, _
vbTab & "If Range(""A1"").Value > 0 Then " & vbCrLf & _
vbTab & vbTab & "Msgbox ""Hi""" & vbCrLf & _
vbTab & "End If"

End With

End Sub

Thank you in advance for you assistance.
--
Larry E. Brueshaber
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      2nd Oct 2006
You would have to start it with a keyboard command or worksheet/workbook event.

"Larry" wrote:

> Playing arround with this routine, It does everything expected by creating
> the button, but when it finnishes it stays in the code module. Is there
> anyway after the routine finnishes that it can revert back to the worksheet.
> The code is as follows:
>
> '-----------------------------------------------------------------
> Sub CreateControlButton()
> '-----------------------------------------------------------------
> Dim oWs As Worksheet
> Dim oOLE As OLEObject
>
> Set oWs = ActiveSheet
>
> Set oOLE =
> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
> Left:=200, Top:=100, Width:=80, Height:=32)
>
> 'To set with a cell
> 'With Range("H2")
> ' Set oOLE =
> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
> ' Left:=.Left, Top:=.Top, Width:=.Width,
> Height:=.Height)
> 'End With
>
> With oOLE
> .Object.Caption = "Run myMacro"
> .Name = "myMacro"
> End With
>
> With ThisWorkbook.VBProject.VBComponents(oWs.CodeName).CodeModule
> .InsertLines .CreateEventProc("Click", oOLE.Name) + 1, _
> vbTab & "If Range(""A1"").Value > 0 Then " & vbCrLf & _
> vbTab & vbTab & "Msgbox ""Hi""" & vbCrLf & _
> vbTab & "End If"
>
> End With
>
> End Sub
>
> Thank you in advance for you assistance.
> --
> Larry E. Brueshaber

 
Reply With Quote
 
=?Utf-8?B?TGFycnk=?=
Guest
Posts: n/a
 
      5th Oct 2006
Thank you for your timely response
--
Larry E. Brueshaber


"Larry" wrote:

> Playing arround with this routine, It does everything expected by creating
> the button, but when it finnishes it stays in the code module. Is there
> anyway after the routine finnishes that it can revert back to the worksheet.
> The code is as follows:
>
> '-----------------------------------------------------------------
> Sub CreateControlButton()
> '-----------------------------------------------------------------
> Dim oWs As Worksheet
> Dim oOLE As OLEObject
>
> Set oWs = ActiveSheet
>
> Set oOLE =
> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
> Left:=200, Top:=100, Width:=80, Height:=32)
>
> 'To set with a cell
> 'With Range("H2")
> ' Set oOLE =
> ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
> ' Left:=.Left, Top:=.Top, Width:=.Width,
> Height:=.Height)
> 'End With
>
> With oOLE
> .Object.Caption = "Run myMacro"
> .Name = "myMacro"
> End With
>
> With ThisWorkbook.VBProject.VBComponents(oWs.CodeName).CodeModule
> .InsertLines .CreateEventProc("Click", oOLE.Name) + 1, _
> vbTab & "If Range(""A1"").Value > 0 Then " & vbCrLf & _
> vbTab & vbTab & "Msgbox ""Hi""" & vbCrLf & _
> vbTab & "End If"
>
> End With
>
> End Sub
>
> Thank you in advance for you assistance.
> --
> Larry E. Brueshaber

 
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
Control Button to Create a New Record in Another Form =?Utf-8?B?bnl0d29kZWVz?= Microsoft Access 16 2nd Nov 2007 04:41 PM
How do I create a control button?? =?Utf-8?B?TWVraW5uaWs=?= Microsoft Excel Programming 7 10th Oct 2007 09:22 PM
Create button control at runtime WebNewsReader Microsoft VB .NET 4 15th Dec 2006 08:41 PM
How do I create a button or control that will automatically go to =?Utf-8?B?Um9nZXI=?= Microsoft Excel Worksheet Functions 1 29th Oct 2004 01:31 AM
create commandbar / control button using codes tango Microsoft Excel Programming 0 26th Oct 2004 01:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:38 AM.