excel_vba_±à³Ì½Ì³Ì(ÍêÕû°æ)-µÚ35ÕÂ
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
°´Å¥ÉèÖá¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
vbOKOnly¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡0¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡½öÏÔʾȷ¶¨°´Å¥£¬ÕâÊÇĬÈÏÖµ¡¡¡¡
vbOKCancel¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾȷ¶¨ºÍÈ¡Ïû°´Å¥¡¡¡¡
vbAbortRetryIgnore¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾÖÕÖ¹£¬ÖØÊԺͺöÂÔ°´Å¥¡¡¡¡
vbYesNoCancel¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾÊÇ£¬·ñºÍÈ¡Ïû°´Å¥¡¡¡¡
vbYesNo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾÊǺͷñ°´Å¥¡¡¡¡
vbRetryCancel¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡5¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾÖØÊÔºÍÈ¡Ïû°´Å¥¡¡¡¡
ͼ±êÉèÖá¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
vbCritical¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡16¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾÖØÒªÐÅϢͼ±ê¡¡¡¡
vbQuestion¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡32¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾÎʺÅͼ±ê¡¡¡¡
vbExclamation¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡48¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾ¾¯¸æÐÅϢͼ±ê¡¡¡¡
vbInformation¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡64¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÔʾÐÅϢͼ±ê¡¡¡¡
ĬÈÏ°´Å¥ÉèÖá¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
vbDefaultButton1¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡0¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡µÚÒ»¸ö°´Å¥ÊÇȱʡֵ¡¡¡¡
vbDefaultButton2¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡256¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡µÚ¶þ¸ö°´Å¥ÊÇȱʡֵ¡¡¡¡
vbDefaultButton3¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡512¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡µÚÈý¸ö°´Å¥ÊÇȱʡֵ¡¡¡¡
vbDefaultButton4¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡768¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡µÚËĸö°´Å¥ÊÇȱʡֵ¡¡¡¡
ÐÅÏ¢¿òÐÎʽ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
vbApplicationModal¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡0¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ó¦ÓóÌÐòÇ¿ÖÆ·µ»Ø£»Ó¦ÓóÌÐòÒ»Ö±±»¹ÒÆð£¬Ö±µ½¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡92¡¡
¡¡¡Ò³Ãæ¡¡109¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Óû§¶ÔÏûÏ¢¿ò×÷³öÏìÓ¦²Å¼ÌÐø¹¤×÷¡£¡¡¡¡
vbSystemModal¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4096¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏµÍ³Ç¿ÖÆ·µ»Ø£»È«²¿Ó¦ÓóÌÐò¶¼±»¹ÒÆð£¬Ö±µ½Óá¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»§¶ÔÏûÏ¢¿ò×÷³öÏìÓ¦²Å¼ÌÐø¹¤×÷¡£¡¡¡¡
MsgBoxÏÔʾµÄÆäËüÉèÖá¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
vbMsgBoxHelpButton¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡16384¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡½«Help°´Å¥Ìí¼Óµ½ÏûÏ¢¿ò¡¡¡¡
vbMsgBoxSetForeground¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡65536¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ö¸¶¨ÏûÏ¢¿ò´°¿Ú×÷Ϊǰ¾°´°¿Ú¡¡¡¡
vbMsgBoxRight¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡524288¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Îı¾ÎªÓÒ¶ÔÆë¡¡¡¡
vbMsgBoxRtlReading¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1048576¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ö¸¶¨Îı¾Ó¦ÎªÔÚÏ£²®À´ºÍ°¢À²®ÓïϵͳÖеĴÓÓÒ¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡µ½×óÏÔʾ¡¡¡¡
¡¡¡¡
ÄãʲôʱºòÓ¦¸ÃʹÓð´Å¥²ÎÊýÄØ£¿¼ÙÉèÄãÒªÓû§¶ÔÒ»¸öÎÊÌâ»Øµ½¡°ÊÇ¡±»ò¡°·ñ¡±£¬ÄãµÄÐÅÏ¢¿ò¾ÍÐè¡¡
ÒªÁ½¸ö°´Å¥£¬µ±ÐÅÏ¢¿òÓÐÒ»¸öÒÔÉϵݴťʱ£¬¾ÍÐèÒª½«ÆäÖÐÒ»¸öÉèÖÃΪȱʡֵ£¬µ±Óû§»Ø³µµÄʱºò£¬¡¡
Õâ¸öĬÈϵİ´Å¥¾Í»á×Ô¶¯µØ±»Ñ¡ÉÏ¡£¡¡¡¡
ÒòΪ£¬Äã¿ÉÒÔÏÔʾ¸÷ÖÖ¸÷ÑùµÄÐÅÏ¢£¨ÖØÒª£¬¾¯¸æ£¬ÐÅÏ¢£©£¬ËùÒÔ£¬ÄãÐèҪͨ¹ý°´Å¥²ÎÊýÉèÖÃͼÐδú¡¡
±í£¨Í¼±ê£©À´Ö¸Ã÷ÐÅÏ¢µÄÖØÒªÐÔ¡£¡¡¡¡
³ýÁËÐÅÏ¢ÀàÐÍÖ®Í⣬°´Å¥²ÎÊý»¹¿ÉÒÔÉèÖÃÊÇ·ñÓû§±ØÐëÏȹرոÃÐÅÏ¢¿ò²ÅÄÜÇл»µ½ÁíÍâµÄÓ¦Óó̡¡
Ðò¡£ºÜ¶àÇé¿öÏ£¬Óû§ÐèÒªÔÚ¶ÔÐÅÏ¢¿òµÄÎÊÌâ×ö³ö·´Ó¦Ö®Ç°£¬Çл»µ½ÁíÍâµÄ³ÌÐò»òÕß½øÐÐÁíÍâµÄ²Ù¡¡
×÷¡£Èç¹ûÕâ¸öÐÅÏ¢¿òÊÇÓ¦ÓóÌÐòģʽ£¨vbApplication¡¡Modal£©µÄ»°£¬Óû§±ØÐëÏȹرոÃÐÅÏ¢¿òºó¡¡
²ÅÄܼÌÐøʹÓÃÄãµÄÓ¦ÓóÌÐò¡£ÁíÒ»·½Ã棬Èç¹ûÄãÏëÒªÔÚÓû§¶ÔÐÅÏ¢¿òÏìӦ֮ǰ£¬½«ËùÓÐÓ¦ÓóÌÐò¹Ò¡¡
Æð£¬ÄÇôÄã±ØÐëÔÚ°´Å¥²ÎÊýÀï¼ÓÉÏϵͳǿÖÆ·µ»ØÉèÖá¡£¨vbSystemModal£©¡£°´Å¥²ÎÊýµÄÉèÖ÷ÖΪÎå×飺¡¡
°´Å¥ÉèÖã¬Í¼±êÉèÖã¬Ä¬ÈÏ°´Å¥ÉèÖã¬ÐÅÏ¢¿òÐÎʽºÍÆäËüµÄMsgBoxÏÔʾÉèÖ㨲μûͼ4£1£©¡£Ã¿×é¡¡
ÉèÖÃÀïÃæÖ»ÄÜÑ¡Ò»¸ö¼ÓÈë°´Å¥²ÎÊýÀïÃæ¡£Äã¿ÉÒÔ½«Ã¿ÖÖÐèÒªµÄÉèÖüӺÍÆðÀ´£¬À´ÉèÖð´Å¥²ÎÊý£¬Àý¡¡
È磬ҪÏÔʾһ¸ö´øÁ½¸ö°´Å¥£¨¡°ÊÇ¡±ºÍ¡°·ñ¡±£©£¬ÎʺÅͼ±êÒÔ¼°½«¡°·ñ¡±°´Å¥ÉèÖÃΪȱʡֵµÄÐÅÏ¢¿ò£¬¡¡
Äã¿ÉÒÔÔÚ±í4£1Àï²éÕÒÏàÓ¦µÄÖµ²¢ÇÒ¼ÓºÍÆðÀ´£¬ÄãÓ¦¸ÃµÃµ½292£¨4£«32£«256£©¡£Äã¿ÉÒÔÔÚÁ¢¼´´°¿ÚÀï¡¡
ÃæÊäÈëÏÂÁдúÂ룬¿ìËٲ鿴ʹÓøüÆËãµÄ°´Å¥²ÎÊýµÄÐÅÏ¢¿ò£º¡¡¡¡
MsgBox¡¡¡¨Do¡¡you¡¡want¡¡to¡¡proceed£¿¡¨£»¡¡292¡¡¡¡
ÏÂÃæÏÔʾµÄ¾ÍÊÇÐÅÏ¢¿ò½á¹û¡£µ±ÄãÖ±½ÓʹÓüӺÍÆðÀ´µÄÖµ×÷Ϊ²ÎÊýʱ£¬ÄãµÄ³ÌÐò¿É¶ÁÐԾͲ»¸ßÁË£¬¡¡
ÒòΪûÓвο¼Ë÷Òý±í¸ñ¹©Äã¼ì²é292±³ºóµÄÒâ˼¡£Òª¸ÄÉÆÄãÐÅÏ¢¿òº¯ÊýµÄ¿É¶ÁÐÔ£¬×îºÃʹÓó£Á¿£¬¡¡
¶ø²»ÒªÊ¹ÓÃËüÃǵÄÖµ£¬ÀýÈ磬ÔÚÁ¢¼´´°¿ÚÊäÈëÏÂÁÐÐ޸ĺóµÄÓï¾ä£º¡¡¡¡
MsgBox¡¡¡¨Do¡¡you¡¡want¡¡to¡¡proceed£¿¡¨£»¡¡vbYesNo¡¡£«¡¡vbQuestion¡¡£«¡¡vbDefaultButton2¡¡¡¡
ÉÏÃæµÄÓï¾äµÃµ½Èçͼ4£9ËùʾµÄÏàͬ½á¹û¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ͼ4£9¡¡Äã¿ÉÒÔʹÓÿÉÑ¡µÄ°´Å¥²ÎÊýÀ´È·¶¨ÐÅÏ¢¿òÉϵİ´Å¥¸öÊý¡¡¡¡¡¡
ÏÂÃæµÄÀý×Óʾ·¶ÈçºÎÔÚVB¹ý³ÌÀïʹÓð´Å¥²ÎÊý£º¡¡¡¡
1¡£¡¡¡¡ÔÚ¹¤³ÌMyFunctions¡¡£¨Chap04¡£xls£©ÀïÌí¼ÓÒ»ÐÂÄ£¿é£¬²¢ÃüÃûΪSample7¡¡¡¡
2¡£¡¡¡¡¼¤»îSample7Ä£¿é£¬²¢ÇÒÊäÈëÈçÏÂ×Ó³ÌÐòMsgYesNo£º¡¡¡¡
Sub¡¡MsgYesNo£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡question¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡myButtons¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡question¡¡=¡¡¡¨ÊÇ·ñÒª´ò¿ªÒ»¸öй¤×÷²¾£¿¡¨¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡myButtons¡¡=¡¡vbYesNo¡¡£«¡¡vbQuestion¡¡£«¡¡vbDefaultButton2¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡MsgBox¡¡question£»¡¡myButtons¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
ÔÚÉÏÃæµÄ×Ó³ÌÐòÀ±äÁ¿question´¢´æÁËÄãµÄÐÅÏ¢Îı¾£¬¶ø°´Å¥²ÎÊýµÄÉèÖÃÔò´¢´æÓÚ±äÁ¿¡¡
myButtons¡£³ýÁËʹÓó£Á¿Ãû³ÆÖ®Í⣬Ä㻹¿ÉÒÔʹÓÃËüÃǵÄÖµ£¬ÀýÈçÏÂÃæµÄ£º¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡93¡¡
¡¡¡Ò³Ãæ¡¡110¡
myButtons¡¡=¡¡4¡¡£«¡¡32¡¡£«¡¡256¡¡¡¡
µ«ÊÇ£¬Ã÷È·ÁË°´Å¥³£ÊýµÄ³£Á¿Ãû³ÆµÄ»°£¬Äã¿ÉÒÔʹÄãµÄ³ÌÐò¶ÔÄã×Ô¼ºÒÔ¼°½«À´¿ÉÄÜҪʹÓøóÌÐòµÄ¡¡
ÈËÀ´Ëµ¸üÈÝÒ×Àí½â¡£±äÁ¿questionºÍmyButtonsÓÃ×÷MsgBoxº¯ÊýµÄ²ÎÊý¡£ÔËÐиóÌÐòºó£¬Ä㽫¿´µ½¡¡
Èçͼ4£9ËùʾµÄ½á¹û¡£×¢Ò⣬ÏÖÔÚ°´Å¥¡°·ñ¡±ÊDZ»Ñ¡Öеģ¬ËüÊǸöԻ°¿òµÄĬÈÏ°´Å¥£¬Èç¹ûÄã°´Ï¡¡
»Ø³µ£¬Excel½«¸ÃÐÅÏ¢¿ò´ÓÆÁÄ»ÉÏÒƳý£¬ÒòΪMsgBoxº¯ÊýºóÃæûÓÐÈκÎÖ¸ÁËùÒÔ£¬²»»á·¢ÉúÆäËü¡¡
²Ù×÷¡£½«Ä¬ÈÏ°´Å¥»»³ÉvbDefaultButton1ÉèÖ㬿ÉÒÔ¸ü¸ÄĬÈÏ°´Å¥¡£¡¡¡¡
MsgBoxº¯ÊýµÄµÚÈý¸ö²ÎÊýÊDZêÌ⣬ËäÈ»ÕâÒ²ÊǸö¿ÉÑ¡²ÎÊý£¬µ«ÊÇËüºÜ·½±ã£¬ÒòΪµ±ÄãºöÂÔËüÃÇ£¨Ä¬¡¡
ÈÏΪMicrosoft¡¡Excel£©Ê±£¬¾Í²»Äܸø³ÌÐòÌṩ¿ÉÊÓÌáʾ¡£Äã¿ÉÒÔʹÓÃÕâ¸ö²ÎÊý£¬½«±êÌâÀ¸ÉèÖÃΪ¡¡
ÄãÏëÒªµÄÈκÎÎÄ×Ö¡£¼ÙÉèÄãÒª¹ý³ÌMsgYesNoÏÔʾ±êÌâΪ¡°Ð¹¤×÷²¾¡±£¬ÏÂÃæµÄ¹ý³ÌMsgYesNo2ʾ·¶Èç¡¡
ºÎʹÓñêÌâ²ÎÊý£º¡¡¡¡
Sub¡¡MsgYesNo2£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡question¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡myButtons¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡myTitle¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡question¡¡=¡¡¡¨Do¡¡you¡¡want¡¡to¡¡open¡¡a¡¡new¡¡workbook£¿¡¨¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡myButtons¡¡=¡¡vbYesNo¡¡£«¡¡vbQuestion¡¡£«¡¡vbDefaultButton2¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡myTitle¡¡=¡¡¡¨New¡¡workbook¡¨¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡MsgBox¡¡question£»¡¡myButtons£»¡¡myTitle¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
±êÌâ²ÎÊýÎı¾´¢´æÓÚ±äÁ¿myTitle¡£Èç¹ûÄãûÓÐÃ÷È·±êÌâ²ÎÊýµÄÄÚÈÝ£¬VB½«Ä¬ÈÏÏÔʾΪ¡°Microsoft¡¡¡¡
Excel¡±¡£×¢Ò⣬²ÎÊýÊÇ»ùÓÚMsgBoxº¯Êý¾ö¶¨µÄ˳ÐòÁгöµÄ£¬Èç¹ûÄãÒª°´Äã×Ô¼ºµÄ˳ÐòÁгöÕâЩ²ÎÊý¡¡
µÄ»°£¬Äã¾Í±ØÐ뽫²ÎÊýÃû³ÆÒ»Æðд³ö£¬ÀýÈ磺¡¡¡¡
MsgBox¡¡title£º=myTitle£»¡¡prompt£º=question£»¡¡buttons£º=myButtons¡¡¡¡
ºóÃæÁ½¸ö²ÎÊý¡ª¡ª°ïÖúÎļþ£¨helpfile£©ºÍÉÏÏÂÎÄ£¨context£©¡ª¡ª¾³£ÎªÄÇЩ¶ÔWindows»·¾³Ïµġ¡
°ïÖúÎļþºÜÊìϤµÄ³ÌÐòԱʹÓᣲÎÊýhelpfileÖ¸Ã÷ij¸ö°üº¬ÄãÒªÏÔʾ¸øÓû§µÄ¸½¼ÓÐÅÏ¢µÄ¾ßÌå°ïÖú¡¡
ÎļþµÄÃû³Æ£¬µ±ÄãÃ÷È·ÁËÕâ¸ö²ÎÊýºó£¬Help°´Å¥¾Í»áÔÚÐÅÏ¢¿òÉÏÏÔʾ³öÀ´¡£µ±ÄãʹÓÃhelpfile²ÎÊý¡¡
ʱ£¬ÄãͬʱҲʹÓÃcontext²ÎÊý¡£Õâ¸ö²ÎÊý±íÃ÷ÔÚ°ïÖúÎļþÀïÄãÒªÏÔʾµÄÄǸö°ïÖúÖ÷Ìâ¡£¼ÙÉè¡¡
Help¡£hlpÊÇÄã´´½¨µÄ°ïÖúÎļþ£¬55ÊÇÄãҪʹÓõİïÖúÖ÷Ì⣬Äã¿ÉÒÔ°´ÕÕÈçÏÂÖ¸ÁîÀ´ÏÔʾÕâЩÐÅÏ¢ÓÚ¡¡
ÐÅÏ¢¿òÉÏ£º¡¡¡¡
MsgBox¡¡title£º=mytitle£»¡¡_¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡prompt£º=question¡¡_¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡buttons£º=mybuttons¡¡_¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡helpFile£º=¡¡¡¨HelpX¡£hlp¡¨£»¡¡_¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡context£º=55¡¡¡¡
ÉÏÃæÖ»ÊÇÒ»ÌõVBAÓï¾ä£¬Ê¹ÓÃÁ¬½Ó·û´ò¶ÏΪºÃ¼¸ÐС£¡¡¡¡
12¡£MsgBox¡¡º¯ÊýµÄÔËÐÐÖµ¡¡¡¡
µ±ÄãÏÔʾֻÓÐÒ»¸ö°´Å¥µÄÐÅÏ¢¿òʱ£¬¿ÉÒÔµã»÷È·¶¨°´Å¥»òÕ߻سµ¼ü½«ÐÅÏ¢¿ò´ÓÆÁÄ»ÉÏÒƳý£¬È»¶ø£¬¡¡
µ±ÐÅÏ¢¿òÓÐÁ½¸ö»òÒÔÉϵݴťʱ£¬ÄãµÄ³ÌÐòÐèÒªÖªµÀ°´µÄÊÇÄĸö°´Å¥¡£Äã¿ÉÒÔ½«ÐÅÏ¢¿ò½á¹û´¢´æÔÚ¡¡
Ò»¸ö±äÁ¿ÉÏÀ´ÊµÏÖ¡£±í4£2¡¡ÏÔʾÁËMsgBoxº¯Êý·µ»ØÖµ¡£¡¡¡¡
±í4£2¡¡MsgBoxº¯Êý·µ»ØÖµ¡¡¡¡
Ñ¡ÔñµÄ°´Å¥¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡³£Êý¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Öµ¡¡¡¡
OK£¨È·¶¨£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡VbOK¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡¡¡¡
Cancel£¨È¡Ïû£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡vbCancel¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡¡¡¡
Abort£¨ÖÕÖ¹£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡vbAbort¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡¡¡¡
Retry£¨ÖØÊÔ£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡vbRetry¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡¡¡¡
Ignore£¨ºöÂÔ£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡vbIgnore¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡5¡¡¡¡
Yes£¨ÊÇ£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡vbYes¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡6¡¡¡¡
No£¨·ñ£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡vbNo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡7¡¡¡¡
¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡94¡¡
¡¡¡Ò³Ãæ¡¡111¡
MsgYesNo3¹ý³ÌÊÇMsgYesNo2¹ý³ÌÐ޸ĺóµÄ°æ±¾£¬Ê¾·¶ÈçºÎÈ·¶¨Óû§°´ÏµÄÊÇÄĸö°´Å¥£º¡¡¡¡
Sub¡¡MsgYesNo3£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡question¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡myButtons¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡myTitle¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡myChoice¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡question¡¡=¡¡¡¨Do¡¡you¡¡want¡¡to¡¡open¡¡a¡¡new¡¡workbook£¿¡¨¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡myButtons¡¡=¡¡vbYesNo¡¡£«¡¡vbQuestion¡¡£«¡¡vbDefaultButton2¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡myTitle¡¡=¡¡¡¨New¡¡workbook¡¨¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡myChoice¡¡=¡¡MsgBox£¨question£»¡¡myButtons£»¡¡myTitle£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MsgBox¡¡myChoice¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
ÔÚÉÏÃæµÄ¹ý³ÌÀÄ㽫MsgBoxº¯ÊýµÄ½á¹û¸³¸ø±äÁ¿myChoice¡£×¢Ò⣬ÏÖÔÚ£¬MsgBoxº¯ÊýµÄ²ÎÊýÁÐÔÚ¡¡
À¨ºÅÀïÃ棺¡¡¡¡
myChoice¡¡=¡¡MsgBox£¨question£»¡¡myButtons£»¡¡myTitle£©¡¡¡¡
µ±ÄãÔËÐÐMsgYesNo3ʱ£¬³öÏÖ´øÓÐÁ½¸ö°´Å¥µÄÐÅÏ¢¿ò£¬µ±Äãµã»÷¡°ÊÇ¡±Ê±£¬MsgBox¡¡myChoice½«ÏÔʾ¡¡
Êý×Ö6£»µ±µã»÷¡°·ñ¡±ÔòµÃµ½Êý×Ö7¡£Ä㽫ÔÚµÚÎåÕÂÀïÃæѧϰÈç¹ûÈóÌÐò¸ù¾Ý°´Å¥µÄÑ¡Ôñ½øÐв»Í¬µÄ¡¡
ÈÎÎñ¡£¡¡¡¡
¼¼ÇÉ4£11¡¡MsgBoxº¯Êý¡ª¡ªÊ¹Óû¹ÊDz»Ê¹ÓÃÀ¨ºÅ£¿¡¡¡¡
µ±ÄãÐèҪʹÓÃMsgBoxº¯Êý·µ»ØµÄ½á¹ûʱ£¬ÐèҪʹÓÃÀ¨ºÅ½«¸Ãº¯ÊýµÄ²ÎÊý°üÀ¨ÆðÀ´¡£²»Ê¹ÓÃÀ¨ºÅ£¬Òâ¡¡
ζ×ÅÄã¸æËßVBÄ㽫ºöÂԸú¯ÊýµÄ½á¹û¡£µ±MsgBoxº¯Êý°üº¬Á½¸ö»òÒÔÉϵݴťʱ£¬ÄãºÜ¿ÉÄÜÏëҪʹÓá¡
¸Ãº¯ÊýµÄ½á¹û¡£¡¡¡¡
13¡£Ê¹Óá¡InputBox¡¡º¯Êý¡¡¡¡
InputBoxº¯ÊýÏÔʾһ¸öÐÅÏ¢ÌáʾÓû§ÊäÈëÊý¾Ý£¬Õâ¸ö¶Ô»°¿òÓÐÁ½¸ö°´Å¥¡ª¡ª¡°È·¶¨¡±ºÍ¡°È¡Ïû¡±£¬¡¡
µ±Äãµã»÷È·¶¨Ê±£¬InputBoxº¯Êý·µ»ØÓû§ÊäÈëÔÚÐÅÏ¢¿òÀïµÄÐÅÏ¢£»µ±Äãµã»÷È¡Ïûʱ£¬º¯ÊýÔò·µ»Ø¿Õ¡¡
×Ö·û´®£¨¡±¡¡¡±£©¡£InputBoxº¯ÊýµÄÓ