资源描述:
《第7章使用对话框代码【超实用VBA】》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第7章使用对话框范例113使用Msgbox函数显示消息框SubMymsg()DimMymsgAsIntegerMymsg=MsgBox("文件即将关闭,是否保存所作的修改?",vbYesNoCancel+vbQuestion)SelectCaseMymsgCasevbYesThisWorkbook.SaveCasevbNoThisWorkbook.Saved=TrueCasevbCancelExitSubEndSelectThisWorkbook.CloseEndSub范例114自动关闭的消息框114-1使用WshShell.Popup方法显示消息框SubAutoClose()D
2、imMyShellAsObjectSetMyShell=CreateObject("Wscript.Shell")MyShell.Popup"程序已执行完毕!",2,"运行提示",64SetMyShell=NothingEndSub114-2使用API函数显示消息框PublicDeclareFunctionSetTimerLib"user32"(ByValhWndAsLong,ByValnIDEventAsLong,ByValuElaspeAsLong,ByVallpTimerFuncAsLong)AsLongPublicDeclareFunctionKillTimerLib"u
3、ser32"(ByValhWndAsLong,ByValnIDEventAsLong)AsLongDimMyTimerAsLong83SubAutoClose()MyTimer=SetTimer(0,0,2000,AddressOfCloseMsg)MsgBox"程序已执行完毕!",64EndSubSubCloseMsg(ByValhWndAsLong,ByValuMsgAsLong,ByValideventAsLong,ByValSystimeAsLong)Application.SendKeys"~",TrueKillTimer0,MyTimerEndSub范例115使用In
4、putBox函数输入数据SubMyInput()DimStrAsStringStr=InputBox(prompt:="请输入数据:")IfLen(Trim(Str))>0ThenCells(Rows.Count,1).End(xlUp).Offset(1,0)=StrEndIfEndSubPublicDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLongPublicDeclareFunctionFindWind
5、owExLib"user32"Alias"FindWindowExA"(ByValhWnd1AsLong,ByValhWnd2AsLong,ByVallpsz1AsString,ByVallpsz2AsString)AsLongPublicDeclareFunctionSendMessageLib"user32"Alias"SendMessageA"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,lParamAsAny)AsLongPublicDeclareFunctiontimeSetEventLib"winmm.dll"(
6、ByValuDelayAsLong,ByValuResolutionAsLong,ByVallpFunctionAsLong,ByValdwUserAsLong,ByValuFlagsAsLong)AsLongPublicDeclareFunctiontimeKillEventLib"winmm.dll"(ByValuIDAsLong)AsLongPublicDeclareFunctionGetTickCountLib"kernel32"()AsLongPublicConstEM_SETPASSWORDCHAR=&HCCPubliclTimeIDAsLongSubTimeProc
7、(ByValuIDAsLong,ByValuMsgAsLong,ByValdwUserAsLong,ByValdw1AsLong,ByValdw2AsLong)DimhwdAsLonghwd=FindWindow("#32770","MicrosoftExcel")Ifhwd<>0Then83hwd=FindWindowEx(hwd,0,"edit",vbNullString)SendMessagehwd,EM_SETPASSWORDCHAR,42,0timeKillEventl