ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[Âà¶K] VBA-¦Û­qCommandBarButton¨Æ¥ó (´¡¤J¦Û°Ê¹Ï¤å¶°)

[Âà¶K] VBA-¦Û­qCommandBarButton¨Æ¥ó (´¡¤J¦Û°Ê¹Ï¤å¶°)

­ìµoªíªÌ¡Gleonchou (2005-05-28)

³o¦¸ªº»Ý¨D¬O¦Û­q¤@­Ó¤U©Ô¦¡¥\¯àªí¡A¥[¤J¼Æ­Ó«ö¶s¡F«ö¶sªº°Ê§@¬O¦b¤å¥ó¤¤´¡¤J¥H«ö¶s¦WºÙ¬°¦Wªº¦Û°Ê¹Ï¤å¶°¶µ¥Ø¡C
¥Ñ©ó CommandBarButtonªº OnAtion ¤£±µ¨ü±a°Ñ¼Æªº¥¨¶°¡A¤S¤£·Q­«½Æ¼g¦h­ÓÃþ¦üªº¥¨¶°¡A©Ò¥H¦³¥H¤Uªº¸Ñ¨M¤è®×¡C

¨ä¹ê¦b«Ø¥ßCommandBarButton®Éª½±µ«ü©w爲¦Û°Ê¹Ï¤å¶°¶µ¥Ø¬O¥i¦æªº¡A¦ý¦pªG§A¯uªº¤£·Q¨º¼Ë°µ¡A¨º»ò¥H¤U¤¶²Ð¦Û­q CommandBarButton ªº Click ¨Æ¥ó¡G

1. ·s¼W¤@­Óª«¥óÃþ§O¼Ò²Õ (¨Ï¥Î¹w³]¦WºÙClass1)¡A¥]§t¥H¤U¥N½X --
  1. Public WithEvents cmdBarButton As Office.CommandBarButton
  2. Private Sub cmdBarButton_Click(ByVal Ctrl As Office.CommandBarButton, _
  3. ¡@¡@CancelDefault As Boolean)
  4. ¡@¡@InsertAutoText Ctrl.Caption
  5. ¡@¡@CancelDefault = True
  6. End Sub
½Æ»s¥N½X
2. «Ø¥ß¤U©Ô¦¡¥\¯àªí¥¨¶°©Ò¦b¼Ò²Õªºµ{¦¡½X --
  1. Dim btnClass() As New Class1
  2. Public Sub CreateCommandBarPopup()
  3. ¡@¡@Dim objCommandBarControl As Office.CommandBarControl
  4. ¡@¡@Dim objCommandBarButton As Office.CommandBarButton
  5. ¡@¡@
  6. ¡@¡@'§R°£­ì¦³ªº¤U©Ô¦¡¥\¯àªí±±¨î¶µ
  7. ¡@¡@For Each objCommandBarControl In CommandBars("Standard").Controls
  8. ¡@¡@¡@¡@If objCommandBarControl.Caption = "§Úªº¥\¯àªí\" Then
  9. ¡@¡@¡@¡@¡@ objCommandBarControl.Delete
  10. ¡@¡@¡@¡@End If
  11. ¡@¡@Next objCommandBarControl
  12. ¡@¡@
  13. ¡@¡@'¦b"¤@¯ë"¤u¨ã¦C«Ø¥ß¤U©Ô¦¡¥\¯àªí¤Î«ö¶s
  14. ¡@¡@With CommandBars("Standard").Controls.Add(msoControlPopup)
  15. ¡@¡@¡@¡@.Caption = "§Úªº¥\¯àªí\\"
  16. ¡@¡@¡@¡@myCount = 0
  17. ¡@¡@¡@¡@For Each itm In Array("¼f­p³æ¦ì", "«Ø³]³æ¦ì")
  18. ¡@¡@¡@¡@¡@¡@Set objCommandBarButton = .Controls.Add(msoControlButton)
  19. ¡@¡@¡@¡@¡@¡@With objCommandBarButton
  20. ¡@¡@¡@¡@¡@¡@¡@¡@.Caption = itm
  21. ¡@¡@¡@¡@¡@¡@¡@¡@.Tag = .Caption
  22. ¡@¡@¡@¡@¡@¡@End With
  23. ¡@¡@¡@¡@¡@¡@myCount = myCount + 1
  24. ¡@¡@¡@¡@¡@¡@ReDim Preserve btnClass(1 To myCount)
  25. ¡@¡@¡@¡@¡@¡@'±NCommandBarButton³v¤@³sµ²¨ì¤W­±¦Û©w¸qªºcmdBarButtonª«¥ó
  26. ¡@¡@¡@¡@¡@¡@Set btnClass(myCount).cmdBarButton = objCommandBarButton
  27. ¡@¡@¡@¡@Next itm
  28. ¡@¡@End With
  29. End Sub

  30. Sub InsertAutoText(strAutoText As String)
  31. ' ¦b¥Ø«e¦ì¸m´¡¤J¦Û°Ê¹Ï¤å¶°
  32. ¡@¡@ActiveDocument.AttachedTemplate.AutoTextEntries(strAutoText).Insert Where:=Selection.Range
  33. End Sub
½Æ»s¥N½X
¦p¦¹·í«ö¤U¦Û©w¸q¥\¯àªíªº«ö¶s´N·|IJµoª«¥óÃþ§O¼Ò²ÕClass1 ªºcmdBarButton_Click ¨Æ¥ó¡A¦Û°Ê§P§O¨ä Caption ÄݩʨéI¥s InsertAutoText µ{¦¡¡C
PS.
1. ¬ÛÃöªº¦Û°Ê¹Ï¤å¶°¶µ¥Ø¥²¶·¤w¦s¦b¡A­Y¨S¦³½Ð¥ý«Ø¥ß¡C
2. ¦b¤å¥ó¤¤´¡¤J¦Û°Ê¹Ï¤å¶°ªº¥N½X¤]¥i¥Hª½±µ¼g¦bÃþ¼Ò²Õ Class1 ªº cmdBarButton_Click ¨Æ¥ó¤§¤¤¡C
°¶Ôйq¤l®Ñ,Åwªï§K¶O¤U¸ü°Ñ¦Ò
http://www.twbts.com/ebook/?subject=office
http://www.twbts.com/ebook/?subject=soft
°¶ÔÐÂîѮw---https://www.facebook.com/groups/669579416484096/
¦³¤@®a¬a¥J©±---https://www.facebook.com/sadodona

¦^´_ 1# °¶ÔÐ
¥i§_½Ð±Ðª©¥D¤j¤j
      Excel VBA¸Ì     
      Path1 = Application.ActiveWorkbook.Path      
      ¦bExcel VBA¸Ì À³¦p¦ó¼g»yªk ¥h¥´¶}   path1 & "\A4_3x7.doc"   
                            ¸U¤À·P¿E

TOP

        ÀR«ä¦Û¦b : ­n¤ñ½Ö§ó¨ü½Ö¡D¤£­n¤ñ½Ö§ó©È½Ö¡C
ªð¦^¦Cªí ¤W¤@¥DÃD