Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default macro to add button to a spreadsheet cell

Hello,

I need a macro to add a button to a spreadsheet cell and automatically
assign a macro to it. I understand how to do it manually in Excel, but it's
not easy to adjust the button's rect to fit the cell.

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default macro to add button to a spreadsheet cell

Here is one example you can look over...


Mark Ivey


Sub AddButtonAndMacroToSheet()

' Change this selection as needed
Range("D11").Select

' This will add a button to the activecell
' which was selected in the previous step
ActiveSheet.Buttons.Add(ActiveCell.Left, _
ActiveCell.Top, _
ActiveCell.Width, _
ActiveCell.Height).Select

' This will assign a macro to this button
Selection.OnAction = "Macro1"
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default macro to add button to a spreadsheet cell

Hello,

I am writing to check the status of the issue on your side. Would you mind
letting me know the result of Mark's suggestions? Mark's solution works
well based on my tests. If you need further assistance, feel free to let me
know. I will be more than happy to be of assistance.

Have a great day!

Regards,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default macro to add button to a spreadsheet cell

Hi folks,

I'm pleased to see such a straightforward post about this topic...
However, when I implement this method I get an, "Argument not
optional" message box. I'll give you my code:

Sub AddButtonandMacroToSheet()
Range("I2").Select
ActiveSheet.Buttons.Add(ActiveCell.Left, _
ActiveCell.Top, _
ActiveCell.Width, _
ActiveCell.Height).Select

Selection.OnAction = "GetPPID"
End Sub

Here's the code for my macro:

Function GetPPID(PPID) As String
Const URL As String = _
"https://report.converge.com/dell/internal/check_battery.php?
ppid="
Const FRAG1 As String = "'green'"
Const FRAG2 As String = "</FONT"
Dim msxml As Object
Dim rV, tmp, pos1, pos2

rV = ""

If PPID < "" Then
Set msxml = CreateObject("Microsoft.XMLHTTP")
msxml.Open "Get", URL & PPID, False
msxml.send

tmp = msxml.responseText

pos1 = InStr(tmp, FRAG1)
pos2 = InStr(tmp, FRAG2)

' If pos1 0 And pos2 0 Then
' rV = Left(tmp, pos2 - 1)
' rV = Right(rV, Len(rV) - (pos1 + Len(FRAG2)))
' End If

rV = tmp ' to be parsed later

Set msxml = Nothing
End If

GetPPID = Right(Left(rV, 83), 58)

' example of return string to be parsed
' [center][BR][BR][BR][BR][FONT COLOR='green']
' PPID: THE-BARCODE-HE KEEP AT CONVERGE![/font][BR]
' [BR][HR][BR][BR][FORM ACTION = 'check_battery.php']PPID:
' [INPUT TYPE='text' NAME = 'ppid'][BR][BR][INPUT TYPE='SUBMIT'
' VALUE = ' SUBMIT '][/FORM]

End Function

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default macro to add button to a spreadsheet cell

Jaybird...

I don't think the Selection.OnAction can call a function...

I believe it has to be a Sub.

Mark



"Jaybird" wrote in message
...
Hi folks,

I'm pleased to see such a straightforward post about this topic...
However, when I implement this method I get an, "Argument not
optional" message box. I'll give you my code:

Sub AddButtonandMacroToSheet()
Range("I2").Select
ActiveSheet.Buttons.Add(ActiveCell.Left, _
ActiveCell.Top, _
ActiveCell.Width, _
ActiveCell.Height).Select

Selection.OnAction = "GetPPID"
End Sub

Here's the code for my macro:

Function GetPPID(PPID) As String
Const URL As String = _
"https://report.converge.com/dell/internal/check_battery.php?
ppid="
Const FRAG1 As String = "'green'"
Const FRAG2 As String = "</FONT"
Dim msxml As Object
Dim rV, tmp, pos1, pos2

rV = ""

If PPID < "" Then
Set msxml = CreateObject("Microsoft.XMLHTTP")
msxml.Open "Get", URL & PPID, False
msxml.send

tmp = msxml.responseText

pos1 = InStr(tmp, FRAG1)
pos2 = InStr(tmp, FRAG2)

' If pos1 0 And pos2 0 Then
' rV = Left(tmp, pos2 - 1)
' rV = Right(rV, Len(rV) - (pos1 + Len(FRAG2)))
' End If

rV = tmp ' to be parsed later

Set msxml = Nothing
End If

GetPPID = Right(Left(rV, 83), 58)

' example of return string to be parsed
' [center][BR][BR][BR][BR][FONT COLOR='green']
' PPID: THE-BARCODE-HE KEEP AT CONVERGE![/font][BR]
' [BR][HR][BR][BR][FORM ACTION = 'check_battery.php']PPID:
' [INPUT TYPE='text' NAME = 'ppid'][BR][BR][INPUT TYPE='SUBMIT'
' VALUE = ' SUBMIT '][/FORM]

End Function

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
Create macro with button in excel spreadsheet Lori Excel Worksheet Functions 2 July 24th 08 01:43 PM
Macro hot button in Spreadsheet watchtower Excel Programming 1 February 2nd 07 05:47 PM
Macro hot button in Spreadsheet watchtower Excel Worksheet Functions 3 February 2nd 07 05:27 PM
add a button on a spreadsheet that runs a macro Easygoin123 Excel Programming 1 October 1st 06 09:27 PM


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

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"