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

[µo°Ý] ByVal Target As Range ¥Îªk

[µo°Ý] ByVal Target As Range ¥Îªk

¦U¦ì®v¥S,®v©j,

§Ú¬OEXCEL VBAªºªì¾ÇªÌ,¦Ó§Ú¥ç³£¦³¶R®Ñ¾¤¦Û¾Ç,¦ý¦³TERM "VBA ByVal Target As Range" §Ú¤Wºô,Ú»®Ñ³£¤£¬O¦n©ú¥Õ³o¥y»yªkªº·N«ä,

½Ð¨D¦U¦ì«üÂI

ÁÂÁÂ

¯uªº¸U¤À¦hÁÂML089ª©¥D,JACKQ ¤j¤j,¤£¹½¨ä·Ð¹ï·MÄøªº¤p§Ìµ¹¤©¸Ô²Óªº¸ÑÄÀ...
§Ú²{¦b§ó¥[©ú¥Õ¨ìbyval ªº»yªk¥Î³~,
ÁÂÁ¨â¦ì.......

TOP

about byval  2,3.....
(2) ¦ÛÂ૬ºA
(3)  ¦Ü©óª«¥ó
       ª«¥ó¤£»Ý­n¤À¨­ (  ª«¥ó¦Û¤v·|³B²z  )
       ª«¥ó¤]¤£¾A¦X¦³¤À¨­ (  ®Ä¯à§é¦©  )
so  byval object ½sĶ¾¹¶ÇªºÁÙ¬O¥»´L

TOP

¦^´_ 12# mdr0465


¸É¥R
1. ¨S«Å§i®É¬° ByRef
2. ¥Î()¬A¦í¤Þ¼Æ®É¡A±j­¢¶Ç­È¡C

Sub ¥Dµ{¦¡()
    Dim A%, B%, C%
    Debug.Print
        
    A = 123: B = 456: C = 789
    Debug.Print "¥Dµ{¦¡", A, B, C
   
    Call °Æµ{¦¡((A), (B), C) '(A)¡B(B)±j­¢¶Ç­È
    Debug.Print "°Æµ{¦¡ - 1", A, B, C
   
    Call °Æµ{¦¡(A, B, C)
    Debug.Print "°Æµ{¦¡ - 2", A, B, C
End Sub

Sub °Æµ{¦¡(X%, ByRef Y%, ByVal Z%) '¨S¦³«Å§i®É¤º©w¬°ByRef
    X = 321: Y = 654: Z = 987
End Sub

'Debug.Print
'¥Dµ{¦¡         123           456           789
'°Æµ{¦¡ - 1     123           456           789
'°Æµ{¦¡ - 2     321           654           789
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

cc lai ¤j¤j, jackyq  ¤j¤j

¦Ó®a§Ú¯uªº©ú¥Õbyvalªº¥Îªk,¯uªº¦hÁ§A­Ì¤£¹½¨ä·ÐÀ°¦£¸ÑÄÀ©M´£¨Ñ¦C¤lµ¹§Ú°Ñ¦Ò
¸U¤À·PÁ§A­ÌªºÀ°¦£....
ÁÂÁÂ

TOP

Sub °õ¦æ§Ú()
  '¥Î ByRef µo¥Í ¥»´L«H®§ ³Q ¾F©~2 «§ï¨Æ¥ó
  '¾É­P ¾F©~3, ¾F©~4 ¦¬¨ì¿ù»~«H®§
  '§ï¦¨ ByVal ´N¥i¥HÁ׶}³Q ¾F©~2 «§ï
  
   msg = "§Ú¬O³¯¤p¬ü, ¬P´Á¤é±ß¤W6:00 Åwªï¨Ó§Ú®a»EÀ\"
   µo«H®§µ¹¾F©~1 msg
   µo«H®§µ¹¾F©~2 msg
   µo«H®§µ¹¾F©~3 msg
   µo«H®§µ¹¾F©~4 msg
End Sub


Sub µo«H®§µ¹¾F©~1(ByRef msg)
    MsgBox "¾F©~ 1 ¦¬¨ì«H®§: " + msg
End Sub
Sub µo«H®§µ¹¾F©~2(ByRef msg)
    MsgBox "¾F©~ 2 ¦¬¨ì«H®§: " + msg
   
    msg = "§Ú¬O³¯¤p¬ü, ¬P´Á¤é±ß¤W»EÀ\¦]¬°¦³¨Æºò«æ¨ú®ø"            '¾F©~2 ´c·d«H®§
End Sub
Sub µo«H®§µ¹¾F©~3(ByRef msg)
    MsgBox "¾F©~ 3 ¦¬¨ì«H®§: " + msg
End Sub
Sub µo«H®§µ¹¾F©~4(ByRef msg)
    MsgBox "¾F©~ 4 ¦¬¨ì«H®§: " + msg
End Sub

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-1-28 18:39 ½s¿è

¦^´_ 9# mdr0465
¦b¨ç¦¡¸Ì¤Þ¤J°Ñ¼Æ¦p¬°¶Ç­È¡A«hµL½×¸Ó°Ñ¼Æ¦b¸Ó
¨ç¦¡¸Ì¦p¦óÅܤƳ£¤£·|§ïÅܸӰѼƶǤJ®Éªº¤Þ¤Jªì©l­È¡A
¸Ó½d¨Ò¤º¤§Á|¨Ò¡A¥u¬O§i¶D§A¡Atxt ©Î num ¦b¨ç¦¡¸Ì¤£ºÞ
¥¦«ç»ò²§°Ê³£¤£·|§ïÅܶǤJ·í®Éªºªì©l­È (­ì­È)¡C
¦pªG¥Î¥Õ¸Ü»¡ªº¸Ü¡A´N¦p jackyq  ¤j¤j»¡ªº¡C

TOP

¥»©«³Ì«á¥Ñ mdr0465 ©ó 2016-1-28 18:08 ½s¿è

cc lai®v¥S,
¯uªºÁÂÁ§A­@¤ßªº¸ÑÄÀ,§Ú¥ç³£¦³¤Wºô¦A¤F¸Ñbyval »yªk
¥H§Ú©Ò²z¸Ñ,byval ¬O¤£·|¼vÅTµ{¦¡¤¤¦³¬J¼Æ­È,
¦pªG§ÚµL²z¥Ñ¿ù»~ªº¸Ü,
ËÝtest2 ªº
txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
    num = num - 85
¬O¤£·|¥X²{ªº,¦ý¬O¥Îbyval¬O¨S¦³¼vÅT­ì¦³ªº¼Æ­ÈÅܧ󪺱¡ªp¤U¬°¤°»ò§Ú­ÌÁÙ­n¼g
txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
    num = num - 85

¦Ó¤£¼g¨ä¥Lªº¦r¥y©O??

¤£¦n·N«ä,§Ú¸£µ¬¯uªº«Ü²Â,©Ò¥H·Q½Ð±Ð¦U¦ì¸Ñµª¦h¤Ö¤Ö°ÝÃD.....
ÁÂÁÂ

TOP

byval ¥Î¨Ó«OÅ@¥»´Lªº
¦pªG¥»´L¸ê®Æ«Ü­«­n
¤£¤¹³\³Q¤H«§ï ( read  only )
´N¥i¥H¬£¤À¨­¥X¥h©ßÀYÅSÁy
¸U¤@¤À¨­¦b¥~¦a³Q¥L¤HÅQ­â
¬Æ¦Ü³Q±þ¦º
¬Æ¦ÜÁÙ¦ºªº«ÜºG
¥»´L¨ÌµM·|§¹¦nµL¯Ê

TOP

¦^´_ 6# mdr0465
  1. Sub Test2(ByVal txt As String, ByVal num As Integer)   '  ¶Ç­È  (¼Æ­È Value)
  2.     txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
  3.     num = num - 85
  4. End Sub
½Æ»s¥N½X
¤@¯ë¹ê°È¤W°£«D¶·¦P¨B§ó·sÅÜ¼Æ­È (ByRef)¡A§_«h³£¬O«Å§i¦¨¶Ç¤J­È (ByVal)¡G
¥H¤W½d¨Ò§Yµ¥©ó¥­±`²ßºD¨Ï¥Îªº¡G
  1. Sub Test2(txt As String, num As Integer)   '  ¶Ç­È  (¼Æ­È Value)
  2.     txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
  3.     num = num - 85
  4. End Sub
½Æ»s¥N½X
¦p¦¹»¡©ú¡A©ú¥Õ§_¡H

TOP

        ÀR«ä¦Û¦b : ¶¢¤HµL¼Ö½ì¡A¦£¤HµL¬O«D¡C
ªð¦^¦Cªí ¤W¤@¥DÃD