ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[­ì³Ð] Excel VBA ¿ù»~³B²z¬yµ{(¥þ¹Ï¸Ñ)

[­ì³Ð] Excel VBA ¿ù»~³B²z¬yµ{(¥þ¹Ï¸Ñ)

¥»©«³Ì«á¥Ñ iamaraymond ©ó 2018-5-22 20:49 ½s¿è

¤@¯ë¨Ó»¡¡A·í§Ú­Ìªºµ{¦¡°õ¦æ°_¨Ó¨S¦³¿ù»~®É¡A¥i¥Hª½±µ°õ¦æ¨ì©³


¦ý¦pªG¤£¤p¤ß¦³­Ó¿ù»~®É¡A´N·|±Ò°Ê¡u¿ù»~³B²z¾÷¨î¡v


¨º³o®É­Ô¡A§Ú­Ì¦³3­Ó¤è¦¡¨Ó³B²z¿ù»~
1.on error resume next
2.on error goto [line]
3.on error goto 0

1.on error resume next


­Y¨Ï¥Îon error resume nextªº¸Ü¡A·í¥X²{¿ù»~®É¡AÁöµM¿ù»~³B²z¾÷¨î·|±Ò°Ê¡A¦ý·|°¨¤WÃö³¬
´N¹³¬Æ»ò¨Æ³£¨Sµo¥Í¤@¼ËÄ~Äò°õ¦æ¤U¤@¦æ¡A§¹¥þ¤£·|¸õ¥X¿ù»~°T®§®Ø

2.on error goto [line]


·í¨Ï¥Î³o­Ó»yªk®É¡A­Y¹J¨ì¿ù»~´N·|¸õ¨ì«ü©wªº¦ì¸m¡A¦ý­nª`·Nªº¬O¡A¦¹®É¿ù»~¾÷¨î¨Ã¥¼Ãö³¬!!
¤]´N¬O»¡¡AÁöµMµ{¦¡¥i¥HÄ~Äò°õ¦æ¡A¦ý¿ù»~¾÷¨î¤´µM¬O±Ò°Ê¤¤¡A©Ò¥H¸U¤@¤£¤p¤ß¤S¥X¿ù¡C¡C¡C



³o­Ó®É­Ô¡A¥L´N·|ª½±µ¸õ¥X¿ù»~°T®§®Ø¡A¨Ã¼È°±µ{¦¡¡A³o¤]¬O³\¦h¤H·|«Ü§x´bªº¦a¤è
¤ñ¦p«Ü¦h¤H±`§âon error goto [line] ªº»yªk¼g¶i°j°é¤¤:
  1. Sub test11()

  2. For I = 1 To 3
  3. continue:
  4.     On Error GoTo myErr
  5.     k = 0 / 0
  6. Next
  7. myErr:
  8. k = 1
  9. GoTo continue
  10. End Sub
½Æ»s¥N½X
²Ä¤@¦¸°õ¦æ®É¡A¥i¥H¦¨¥\¸õÂà¨ìmyErr¡A¦ý²Ä¤G¦¸´N¤£¦æ¤F
­ì¦]´N¬O¦¹®É¿ù»~¾÷¨î¤w¸g±Ò°Ê¡A¦b¿ù»~¾÷¨î¤w¸g±Ò°Ê®É
§Y¨Ï§A¥[¤Fon error resume next ¤]¤@¼Ë·|¸õ¥X¿ù»~°T®§®Ø
  1. Sub test12()

  2. For I = 1 To 3
  3.     On Error GoTo myErr
  4.     k = 0 / 0
  5. Next

  6. myErr:
  7. On Error Resume Next
  8. I = 0 / 0

  9. End Sub
½Æ»s¥N½X
¨º­n¦p¦ó§â¿ù»~¾÷¨îÃö³¬©O?
³o®É¦³3­Ó¤èªk
(1)resume:Ãö³¬¿ù»~¾÷¨î¨Ã¦^¨ì¥X¿ùªº¨º¤@¦æ



(2)resume next:Ãö³¬¿ù»~¾÷¨î¨Ã¦^¨ì¥X¿ùªº¤U¤@¦æ



(3)on error goto -1:Ãö³¬¿ù»~¾÷¨î¨ÃÄ~Äò°õ¦æ¤U¤@¦æ



©Ò¥H·í¿ù»~¾÷¨î³QÃö±¼®É¡A­Y¦A¦¸¹J¨ì¿ù»~´N¥i¥HÄ~Äò¥Î«e­±©Ò»¡ªº3­Ó¤è¦¡¨Ó³B²z¿ù»~

3.on error goto 0



on error goto 0·|Ãö³¬¿ù»~¾÷¨î¡A¦ý¸õ¥X¿ù»~°T®§®Ø

¨º³o®É¤j®a¥i¯à´N·|«ÜºÃ´b:
Q:¬JµMon error goto 0·|ª½±µ¸õ¥X¿ù»~°T®§®Ø¡A¬°¤°»òÁÙ­n¨Ï¥Î³o­Ó»yªk©O?
A:¦]¬°¦³®É­Ô¥²¶·¥Î³o­Ó»yªk¨Ó¨ú®øon error resume next ªº¥\¯à

EX:´¿¦³¤H°Ý¹L¦pªG§Ú·Q­n«e¤Q¦æ¥i¥H¸õ¹L¿ù»~¡A¦ý¹L¤F³o¤Q¦æ­n¯à¸õ¥X¿ù»~°T®§®Ø¡A­n«ç»ò°µ©O?

Sub Test()

On error resume next
.
.
.
On error goto 0

End Sub

¦]¦¹³o®É­Ô´N»Ý­n³o­Ó»yªk¨Ó¨ú®øon error resume next


¸É¥R½g:¦p¦ó³B²z¿ù»~?




¤å³¹¨Ó·½:
https://raymondchiendtrt.blogspot.tw/2018/05/vba_14.html#more

°Ñ¦Ò¸ê®Æ:
http://club.excelhome.net/thread-503926-1-1.html
http://club.excelhome.net/forum.php?mod=redirect&goto=findpost&ptid=99895&pid=4506304
http://club.excelhome.net/thread-255631-1-1.html
http://yes.nctu.edu.tw/vb/9_Misc/%E5%8F%AF%E8%99%95%E7%90%86%E7%9A%84%E9%8C%AF%E8%AA%A4.htm
1

µû¤À¤H¼Æ

Excel VBAºô­¶¸ê®Æ¦¬¶°±Ð¾Ç:
http://forum.twbts.com/thread-20848-1-1.html

¥»©«³Ì«á¥Ñ nolookyou ©ó 2018-5-23 09:14 ½s¿è

¦^´_ 1# iamaraymond


    ·PÁª©¤j¥Î¤ßµo¤å¡A¹êÄÝÃø¯à¥i¶Q~
    ¬Ý¨ìon error goto»yªk ·Q¨ì§ÚÁÙ¬O¤¤¤G§¾«Ä®É¼gBasic¬ü¦n®É¥ú...XD

    ªø¤j«á±µÄ²ªºµ{¦¡±M®×º¥¦h¥B¥\¯à»Ý¨D¤é¯qÃe¤j¡A
    ·|µo²{·íªìBasic¤ä´©ªºon error goto¨ä¹ê¨S¦³«Ü¦n¥Î¡A¥Î¤FÁÙ·|¼W¥[µ{¦¡ºûÅ@§xÂZQQ

    ¬Ý°ê¥~¤@¨Ç°ª¤â¼gVBA¡A·|µo²{¥L­Ì¥Îon error©ÎErr¨t¦C¿ù»~³B²z»yªk¡A
    ¦h¥Î¦b¥i¯àµLªk¹w´Áªº1-1000¸¹¨t²Î¿ù»~°µ³B²z¡A
   
    µ{¦¡»Ý¨D³]­pªº¥i¹w´ÁÅÞ¿è¿ù»~¡A¦bºÉ¶q³]·Q¦n¦UºØ¥i¹w´Á°ÝÃD«á¡A
    §â¸û§¹¾ã³B²z¤èªk³£¦bIf...Then...Else ©Î Select Case°µ±¼¡A
    ¦Ó¤ñ¸û¤Ö¨Ì¿àon error goto°µ¿ù»~³B²z¡A
    ¬O¤p§Ìı±o¤ñ¸û¦nªºµ{¦¡¤º¿ù»~³B²z¤è¦¡^^

TOP

¦^´_ 2# nolookyou

·PÁÂnolookyou¤j´£¨Ñªº¸gÅç
¨ä¹ê¤p§Ì­ì¥»«Ü¾á¤ßPO³oºØ¿ù»~³B²zªº¤å·|¤£·|¤Ó¬\Àê¥F¨ýXD
©Ò¥H±zªº·N«ä¬O»¡¤ñ¸û¦nªº¤è¦¡¬O
ª½±µ¥Îon error resume next
±µµÛ¤U­±´Nª½±µ¥Îif©Îselect case»y¥y
·f°terr.numberª½±µ§â¿ù»~³B²z±¼¶Ü?
Excel VBAºô­¶¸ê®Æ¦¬¶°±Ð¾Ç:
http://forum.twbts.com/thread-20848-1-1.html

TOP

¥»©«³Ì«á¥Ñ quickfixer ©ó 2018-5-24 00:52 ½s¿è

¸É¥R¡G¤£¦n·N«ä,µo¤å«á¤~µo²{,§Aªº±Ð¾Ç¸Ì­±´N¦³Err.Description,¦hµo¤F¤@½g¼o¤å

³o¼Ë´N¥i¥H¥Îerr.number  ¿ù»~¥N½X
¤]¥i¥H¥Îerr.description ¿ù»~°T®§

¬Ý¬O­n¥Î¤°»òmsgbox ´£¥Ü,ÁÙ¬O­«¶]µ{¦¡
  1. Sub test()

  2.     On Error GoTo checkid
  3.    
  4.         ' µ{¦¡½X
  5.    
  6.    
  7.    
  8.     Exit Sub
  9.    



  10. checkid:

  11.     If Err.Number <> 0 Then
  12.         Debug.Print Err.Description
  13.         Debug.Print Err.Number
  14.     End If

  15. End Sub
½Æ»s¥N½X

TOP

¦^´_ 3# iamaraymond


    ª©¤j¦­¦w
    ¨ä¹ê§Ú«Øij¯à¤£¥Îon error resume nextªº¸Ü¤]ºÉ¶q§ä¨ä¥L¤èªk³B²z±¼

    ³æ¯Â¥Îif©Îselect case»y¥y + err.number¬O§Ú¤ñ¸û±`¥Îªº§@ªk¡A
    ³oºØ¤èªk´N¹³VB.net©Î C#¤ºªº try...catch»yªk¡A
    Åýµ{¦¡µ²ºc¤ñ¸û¤£¨º»òÃP´²¡A«á­±¤]¤ñ¸û¦nºûÅ@^^

TOP

        ÀR«ä¦Û¦b : °µ¸Ó°µªº¨Æ¬O´¼¼z¡A°µ¤£¸Ó°µªº¨Æ¬O·Mè¡C
ªð¦^¦Cªí ¤W¤@¥DÃD