Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Adding a command button

I am trying to add a command button to the face of my
spreadsheet then insert some code behind it.

This is the code I am using:

' add the button
Worksheets(1).OLEObjects.Add, _
ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=6, Top:=4, _
Width:=50, Height:=20

Worksheets(1).OLEObjects.BringToFront
' and add the code for emailing
strQuote = Chr$(34)
strEmail = "
strSubject = "Outstanding Purchase Orders"
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & "On error resume next" & vbCrLf
Code = Code & "ThisWorkbook.SendMail Recipients:=" &
strQuote & strEmail & strQuote & ", Subject:=" & strQuote
& strSubject & strQuote & vbCrLf
Code = Code & "End Sub"
With Application.Workbooks(1).VBProject.VBComponents
(1).CodeModule
NextLine = .CountOfLines + 1
'.InsertLines NextLine, Code
End With

I have commented out the 'Insert Lines' line since this
seems to screw up some virus checkers.

The point is that it doesn't get this far. When I run the
code I get an error saying 'Unable to enter break mode at
this time' followed by 'Object does not support this
method' at the point that I am trying to add the button.

The code to add the button was taken from the VBA Help!!

What am I doing wrong??

Thanks in Advance

Roy Thompson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Adding a command button

This might be a stupid suggestion depending on how you intend to use this
button but why create it dynamically. Why not just toggle the visible
property of a button that you have already created. Its a lot easier if you
can get away with it. I use it all the time

I don't know if this helps, but it might be worth a try...

"Roy Thompson" wrote:

I am trying to add a command button to the face of my
spreadsheet then insert some code behind it.

This is the code I am using:

' add the button
Worksheets(1).OLEObjects.Add, _
ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=6, Top:=4, _
Width:=50, Height:=20

Worksheets(1).OLEObjects.BringToFront
' and add the code for emailing
strQuote = Chr$(34)
strEmail = "
strSubject = "Outstanding Purchase Orders"
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & "On error resume next" & vbCrLf
Code = Code & "ThisWorkbook.SendMail Recipients:=" &
strQuote & strEmail & strQuote & ", Subject:=" & strQuote
& strSubject & strQuote & vbCrLf
Code = Code & "End Sub"
With Application.Workbooks(1).VBProject.VBComponents
(1).CodeModule
NextLine = .CountOfLines + 1
'.InsertLines NextLine, Code
End With

I have commented out the 'Insert Lines' line since this
seems to screw up some virus checkers.

The point is that it doesn't get this far. When I run the
code I get an error saying 'Unable to enter break mode at
this time' followed by 'Object does not support this
method' at the point that I am trying to add the button.

The code to add the button was taken from the VBA Help!!

What am I doing wrong??

Thanks in Advance

Roy Thompson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Adding a command button

Jim

Thanks for that but unfortunately I am creating the entire
spreadsheet dynamically each time the sheet is opened -
hence the need to add the button also dynamically.

Roy
-----Original Message-----
This might be a stupid suggestion depending on how you

intend to use this
button but why create it dynamically. Why not just toggle

the visible
property of a button that you have already created. Its a

lot easier if you
can get away with it. I use it all the time

I don't know if this helps, but it might be worth a try...

"Roy Thompson" wrote:

I am trying to add a command button to the face of my
spreadsheet then insert some code behind it.

This is the code I am using:

' add the button
Worksheets(1).OLEObjects.Add, _
ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=6, Top:=4,

_
Width:=50, Height:=20

Worksheets(1).OLEObjects.BringToFront
' and add the code for emailing
strQuote = Chr$(34)
strEmail = "
strSubject = "Outstanding Purchase Orders"
Code = "Sub CommandButton1_Click()" & vbCrLf
Code = Code & "On error resume next" & vbCrLf
Code = Code & "ThisWorkbook.SendMail Recipients:="

&
strQuote & strEmail & strQuote & ", Subject:=" &

strQuote
& strSubject & strQuote & vbCrLf
Code = Code & "End Sub"
With Application.Workbooks(1).VBProject.VBComponents
(1).CodeModule
NextLine = .CountOfLines + 1
'.InsertLines NextLine, Code
End With

I have commented out the 'Insert Lines' line since this
seems to screw up some virus checkers.

The point is that it doesn't get this far. When I run

the
code I get an error saying 'Unable to enter break mode

at
this time' followed by 'Object does not support this
method' at the point that I am trying to add the button.

The code to add the button was taken from the VBA Help!!

What am I doing wrong??

Thanks in Advance

Roy Thompson

.

Reply
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
command button add another command Wanna Learn Excel Discussion (Misc queries) 5 December 7th 08 11:42 PM
Command button AhmetDY Excel Discussion (Misc queries) 1 October 17th 07 11:36 AM
adding a command button to an excel cell? betelguese Excel Discussion (Misc queries) 1 March 22nd 05 03:09 AM
Command Button vs Control Button RGibson Excel Programming 1 October 14th 03 02:24 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 01:57 PM.

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

About Us

"It's about Microsoft Excel"