Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. Dim MyR As Range, MyB As OLEObject
  2. Dim MyR_T As Long, MyR_L As Long
  3.  
  4.  
  5. Set MyR = Cells(i + 1, 11) 'just an example - you get that from your own script
  6. MyR_T = MyR.Top 'capture positions
  7. MyR_L = MyR.Left '...
  8. 'create button
  9. Set MyB = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False)
  10.  
  11.  
  12. 'set main button properties
  13. With MyB
  14.  
  15. .Name = "MyPrecodedButton" 'important - code must exist ... see below
  16. .Object.Caption = "MyCaption"
  17. .Top = MyR_T
  18. .Left = MyR_L
  19. .Width = 50
  20. .Height = 18
  21. .Placement = xlMoveAndSize
  22. .PrintObject = True 'or false as per your taste
  23.  
  24.  
  25. End With
  26.  
  27. Dim MyR As Range, MyB As OLEObject
  28. Dim MyR_T As Long, MyR_L As Long
  29.  
  30.  
  31. Set MyR = Cells(i + 1, 11) 'just an example - you get that from your own script
  32. MyR_T = MyR.Top 'capture positions
  33. MyR_L = MyR.Left '...
  34. 'create button
  35. Set MyB = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False)
  36.  
  37.  
  38. 'set main button properties
  39. With MyB
  40. .OnAction = "interpHere"
  41. .Name = "MyPrecodedButton" 'important - code must exist ... see below
  42. .Object.Caption = "MyCaption"
  43. .Top = MyR_T
  44. .Left = MyR_L
  45. .Width = 50
  46. .Height = 18
  47. .Placement = xlMoveAndSize
  48. .PrintObject = True 'or false as per your taste
  49.  
  50.  
  51. End With
  52.  
  53. Sub interpHere()
  54. MsgBox "hi"
  55. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement