VBA常用代码解析(第四十一讲).docx
《VBA常用代码解析(第四十一讲).docx》由会员分享,可在线阅读,更多相关《VBA常用代码解析(第四十一讲).docx(11页珍藏版)》请在第壹文秘上搜索。
1、VBA常用代码解析(第四十一讲)148在用户窗体上添加菜单在VBA中,用户窗体上是没有菜单的,为了使用方便,我们可以使用APl函数在用户窗体上添加菜单,示例代码如下:PrivateDeclareFunctionFindWindowLib,ser32,Alias,FindWindowA(ByVaIIpCIassNameAsString,ByVaIIpWindowNameAsString)AsLongPrivateDeclareFunctionSetMenuLib,ser32,(ByVaIhwdAsLong,ByVaIhMeuAsLong)AsLongPrivateDeclareFunctionC
2、reateMenuLib,ser32,()AsLongPrivateDeclareFunctionAppendMenuLib,ser32,Alias,AppendMenuA(ByVaIhMeuAsLong,ByVaIwFlagsAsLong,ByVaIWlDNewItemAsLong,ByVaIIpNewItemAsAny)AsLongPrivateDeclareFunctionDestroyMenuLib,ser32(ByVaIhMeuAsLong)AsLongPrivateDeclareFunctionCreatePopupMenuLib,ser32,()AsLongPrivateDecl
3、areFunctionSetWindowLongLib,user32,Alias,SetWindowLongA(ByVaIhwdAsLong,ByVaIlndexAs1.ong,ByVaIdwNewLogAsLong)AsLongPrivateDeclareFunctionGetWindowLongLib,ser32,Alias,GetWindowLongA(ByVaIhwdAsLong,ByVaInlndexAsLong)AsLongPrivateConstGWL_WNDPROC=(-4)PrivateConstMF_STRING=&H0&PrivateConstMF_POPUP=&H10&
4、PrivateConstMF_SEPARATOR=&H800&DimMenuWndAsLong,DumpAsLong,PopupMenuIDAsLong,PopupMenuWndAsLong,MenuIDAsLongPrivateSubUserFormJnitiaIizeOIfVal(AppIication.Version)hwd=FindWindowCThunderXFrame,Me.Caption)Elsehwnd=FindWindowCThunderDFrame,Me.Captio)EndlfMenuWnd=CreateMenuQPopupMenuID=CreatePoppMeu()Du
5、mp=AppedMe(MenWd,MF_STRING+MF.POPUP,PoPUPMenUID,系统设置(&X)Dump=AppedMe(PopupMeulDjMF_STRING,100,保存(&S),)Dump=APPendMenU(POPUPMenUID,MF_STRING,101,备份(&E)Dump=APPendMenU(POPUPMenUID,MF_STRING,102,退出(&X)PopupMenuID=CreatePoppMeu()Dump=AppendMe(MeWnd,MF_STRING+MF_POPUP,POPUPMenUlD会计凭证(&P)Dump=AppendMe(Pop
6、pMenID,MF_STRING,110,录入(&L)Dump=AppendMe(PoppMenID,MF_STRING,111,审核(&C)PopupMenuID=CreatePoppMeu()Dump=AppendMe(MeWdjMF_STRING+MF_POPUP,POPUPMenUlD会计账簿(&Z)Dump=APPendMenU(POPUPMenUID,MF_STRING,112,记账(&T)Dump=AppendMe(PopupMeulDjMF_STRING,113,结账(&J)PopupMenuID=CreatePoppMeu()Dump=AppendMenu(MenuWnc)j
7、MF_STRING+MF.POPUP,POPUPMenUID会计报表(&B)Dump=AppedMeu(PoppMenID,MF_STRING,114,资产负债表(&F)Dump=AppendMe(PoppMenID,MF_STRING,115,损益表(&Y)Dump=SetMeu(hwd,MenuWnd)PreWinProc=GetWindowLog(hwd,GWL_WNDPROC)SetWidowLonghwnd,GWLWNDPRe)C,AddressOfMsgProcessEndSubPrivateSubUSerFormTerminate。DestroyMenuMenuWndDestro
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VBA 常用 代码 解析 第四 十一