|
-------------------Ö£¼ÒÁú±àÒïÓÚMS OFFICE¿ª·¢Îĵµ
¸´ÖƲ˵¥ºÍ¹¤¾ßÀ¸
±ØÐèÓÃVBA´úÂë²ÅÄܸ´ÖÆÏÖÓеŤ¾ßÀ¸¡£Äã¿ÉÒÔÓÃAdd·½·¨´´½¨Ò»¸öºÍÄãÒª¿½±´ÏàͬÀàÐ͵Ť¾ßÀ¸£¬È»ºóÔÙÓÃCommandBarControl¶ÔµÄCopy·½·¨½«Ô´¹¤¾ßÀ¸ÉϵÄÿһ¸öÃüÁî°´Å¥¸´ÖƵ½Ð¹¤¾ßÀ¸ÉÏ£¬ÏÂÃæµÄº¯Êý½«ÊÇÒÔÕâÖÖ·½·¨ÊµÏÖ¸´Öƹ¤¾ßÀ¸£º
strOrigCBName²ÎÊýÊÇÖ¸±»¸´ÖƵÄÔ´¹¤¾ßÀ¸£¬strNewCBName²ÎÊýָй¤¾ßÀ¸µÄÃû³Æ£¬¿ÉÑ¡²ÎÊýblnShowBar¾ö¶¨ÁËй¤¾ßÀ¸ÊÇ·ñÏÔʾ³öÀ´¡£
Function CBCopyCommandBar(strOrigCBName As String, _
strNewCBName As String, _
Optional blnShowBar As Boolean = False) As Boolean
' This procedure copies the command bar named in the strOrigCBName
' argument to a new command bar specified in the strNewCBName argument.
Dim cbrOriginal As CommandBar
Dim cbrCopy As CommandBar
Dim ctlCBarControl As CommandBarControl
Dim lngBarType As Long
On Error GoTo CBCopy_Err
Set cbrOriginal = CommandBars(strOrigCBName)
lngBarType = cbrOriginal.Type
Select Case lngBarType
Case msoBarTypeMenuBar
Set cbrCopy = CommandBars.Add(Name:=strNewCBName, Position:=msoBarMenuBar)
Case msoBarTypePopup
Set cbrCopy = CommandBars.Add(Name:=strNewCBName, Position:=msoBarPopup)
Case Else
Set cbrCopy = CommandBars.Add(Name:=strNewCBName)
End Select
' Copy controls to new command bar.
For Each ctlCBarControl In cbrOriginal.Controls
ctlCBarControl.Copy cbrCopy
Next ctlCBarControl
' Show new command bar.
If blnShowBar = True Then
If cbrCopy.Type = msoBarTypePopup Then
cbrCopy.ShowPopup
Else
cbrCopy.Visible = True
End If
End If
CBCopyCommandBar = True
CBCopy_End:
Exit Function
CBCopy_Err:
CBCopyCommandBar = False
Resume CBCopy_End
End Function
×¢Ò⣺
1.Õâ¸öº¯ÊýµÄstrNewCBName²ÎÊý²»ÄܺÍÏÖÓй¤¾ßÀ¸ÖÐͬÃû£»
2.Èç¹ûÄã¸´ÖÆÒ»¸öµ¯³öʽ²Ëµ¥À¸£¬²¢ÇÒÉèblnShowBar²ÎÊýΪTRUE£¬µ±ÔËÐÐÕâ¸öº¯Êýʱ£¬Õâ¸öµ¯³öʽ²Ëµ¥À¸½«ÏÔʾÔÚµ±Ç°Êó±êµÄλÖ㬸ü¶àµÄ¹ØÓÚÏÔʾµ¯³öʽ²Ëµ¥À¸µÄÐÅÏ¢ºÍÃèÊöÇë²ÎÔÄMicrosoft Office Visual Basic Reference Help Öеġ°ÏÔʾµ¯³öʽ²Ëµ¥À¸¡±Ë÷Òý¡£
|