模块中代码 Option Explicit Sub autoopen() '自动宏,开启WORD时执行 On Error Resume Next '当错误时执行下一步 Application.CommandBars(1).Controls("我的菜单(&M)").Delete '如果已有菜单则删除 Dim Menu As CommandBarControl, SubMenu As CommandBarControl '申明变量 '设定变量类型----下拉菜单,其中1表示本菜单出现在"常用"栏 Set Menu = Application.CommandBars(1).Controls.Add(msoControlPopup, , , , True) With Menu 'with语句可以提高代码可读性及执行效率 .Caption = "我的菜单(&M)" '新菜单的名字,可以随便定义 End With '结束with With Menu.Controls.Add(msoControlButton, 1, , , True) '添加子菜单 .Caption = "日历" '子菜单标题 .OnAction = "日历宏" '子菜单宏名 .FaceId = 481 '子菜单图标 End With With Menu.Controls.Add(msoControlButton, 1, , , True) .Caption = "时钟" .OnAction = "时钟宏" .FaceId = 484 End With With Menu.Controls.Add(msoControlButton, 1, , , True) .Caption = "说明" .OnAction = "说明" .FaceId = 176 .BeginGroup = True End With End Sub Sub 日历宏() '子菜单之宏代码 精美日历.Show 0 '以无模式显示日历窗体 End Sub Sub 时钟宏() 时钟.Show 0 '以无模式显示时钟标题 End Sub Sub 说明() 说明窗体.Show '显示說明标题 End Sub Sub DeleteMenu() '删除新菜单,此处可以不要,前面已有。但为了大家学习置于此处。 Application.CommandBars(1).Controls("我的菜单(&M)").Delete End Sub
窗体中代码: Private Sub UserForm_Initialize() Me.Height = 205 '窗体高度 Me.Width = 237 '窗体宽度 Me.ShockwaveFlash1.Width = 237 'flash高度 Me.ShockwaveFlash1.Width = 237 'falsh宽度 End Sub
Private Sub UserForm_Initialize() Me.ShockwaveFlash1.Width = 396 'flash宽度 Me.ShockwaveFlash1.Height = 51 'flash高度 End Sub
Option Explicit Private Declare Function DrawMenuBar Lib "user32" (ByVal Hwnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Const GWL_STYLE As Long = (-16) Private Const GWL_EXSTYLE = (-20) Private Const WS_CAPTION As Long = &HC00000 Private Const WS_EX_DLGMODALFRAME = &H1& Private Sub UserForm_Initialize() Dim IStyle As Long, Hwnd As Long '******获取窗口句柄****** If Val(Application.Version) < 9 Then Hwnd = FindWindow("ThunderXFrame", Me.Caption) Else Hwnd = FindWindow("ThunderDFrame", Me.Caption) End If '******去除窗体标题栏****** IStyle = GetWindowLong(Hwnd, GWL_STYLE) IStyle = IStyle And Not WS_CAPTION SetWindowLong Hwnd, GWL_STYLE, IStyle DrawMenuBar Hwnd '******去除窗体四周的边框****** ' IStyle = GetWindowLong(Hwnd, GWL_EXSTYLE) And Not WS_EX_DLGMODALFRAME ' SetWindowLong Hwnd, GWL_EXSTYLE, IStyle With Me.ShockwaveFlash1 .Width = 351 'flash宽度 .Height = 264 'flash高度 .Left = -6 'flash左边距 .Top = -6 'flash上边距 End With Me.Height = 255 '窗体高度 Me.Width = 345 '窗体宽度 End Sub
|