????? ??????? ????????? ?? ????????????? Excel ?? Visual Basic ?????????

?????? ????????? ?????? ?????????
???? ???????: 843144 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

????? ???

???? ??? ??????? ????? ??????? ????????? ?? Microsoft Excel ?? Microsoft Visual Basic for ????????????? ?????????.

??????? ????

????????? ?? ????? sub

???? ???? ?? ???? ??????? ?? ?????? ??? ????? ??? ?? ????? ???? ???? ??????? ??????? ??????? ?? ???? ?????? ?????? ?? ???????. ????? ??? ??????? ??????? ??????? ????????? ?? Visual Basic:
  • ??? ??? ????? ?????????.
  • ????????? ????????? ???? ???? ?? ?????? ?????.
  • ??? ???? ???????.

???? ?????? ????? ?? ?????

?? ???? ????? ?????? ????? ?? ????? ??????? ????? Dim . ????? ?????? ?????? ??????? x ? y? ??????? ???????:
Dim x As Integer, y As Integer
?? x ? y ?????? ?????? ?????? ???? ??? ????? ?? Visual Basic ?????? ????? ????? ?????? ??? ???? (2 ???? ??? ? x ? y) ??? ????????? ??????? ?? ??? x ?? y ??? ???? ???-32768 ? 32767.

?????? ??? ???? ?????? ????? ???? ?? ???? ???????? ????? ????? Dim ? ??? ????? ??? ???????? ??? ?????.

??? ?? ???? ??? ???????? ??? ?????? ??? ?? ????????? ???????? ? Visual Basic ???????, ??? ??????? y ??? ???? ???? ?????. ????? ??????? x ??? ?????:
Dim x, y As Integer
????? ?? ?????????? ???? "??? ?????? ?????" ??????.

?????? ?????? ?????? ???? ??????? ???????:
  1. ???? ????? ?? ?????? ?????? ?? ?? ???? ???? ??????.
  2. ??? ????? ???? Visual Basic (???? ALT + F11).
  3. ??? ????? ???????? ???? ????????? ???????.
  4. ???? ???????? ???????? ???????:
    Sub Variable_Test()
    Dim x As Integer, y As Integer
    x = 10
    y = 100
    MsgBox "the value of x is " & x & _
    Chr(13) & "the value of y is " & y
    End Sub
  5. ????? ??????? Variable_Test . ????? ??????? ???????:
    ?? ???? x 10
    ?? ???? y 100
  6. ???? ??? ?????.
  7. ?? ??????? Variable_Test ?????? ????? ??????:
    x = 10
    

    ???:
    x = "error"
    
  8. ????? ??????? Variable_Test .
???? ??? ??? ??????? ??? "???" ??? ??? ???? ????? ????? ????? ??? ?????? ????? ??? ????? ??? ???? x.

???? ??? ????????

???? ?????? ?????? ????? ???????? ?????? ??????:

?? ??? ??????????? ??? ??????
??? ??????????? ????????????? ??????? ??
???? ?????? 2 ???? ???? ?? ???
??? ???? 2 ???? -32768 ??? 32767
???? 4 ???? -2147483648 ??? 2147483647
????? 8 ???? -1.79769313486232 E308 ??? -4.94065645841247 E-324 ????? ???????; 4.94065645841247 E-324 ??? 1.79769313486232 E308 ????? ???????
?????? 8 ???? 477.5808 ??? 922337203685, 477.5807
????? 8 ???? 1 ????? 100 ??? 31 ?????? 9999
????? ????? ?????? 10 + ??? ???????

??? ???????? ?????

??? ?? ???? ??? ?????? ????? ???? ?????? ????? ??? ?? ???? ??????? ??? ????? ??? ???????? Visual Basic ???????? ?????? ??? ???????? ????? ???? ???????. ???? ??? ??? ????? ????????? ???? ?? ??????? ???? ???????? ???:
  • ???? ?? ????? ??? ????????? ??????? ???????? ??????? ??????? ?? ????? ???????.
  • ???? ????? ????????? ????? ???? ????? ????? ????????.
????? ?? ????? ?? ??????? ????? ??? ????? 16 ???? ?? ???????. 16 ???? ?? ??????? ???? ????? ?? ????????? ????? ?? ?? ??????? ??????? ?????.

??????? ????? ??? ??? ?? ??????? Variable_Test ? ???? ??????? ???????:
  1. ????? ????????? ???????? ?? ??????? Variable_Test ???:
    Sub Variable_Test()
    Dim x, y
    x = "string"
    y = 1.23
    MsgBox "the value of x is " & x & _
    Chr(13) & "the value of y is " & y
    End Sub
    
  2. ????? ??????? Variable_Test .
?? ????? ??? ???? ???? ????? ?? ??? ??? ??????? ????? x ? y.

?????? ????? ???? ??? ???? ????? ?????? ????? ??????? ?? ???? ???? ????????? x ? y ????? ?????? ?????? ?????:
Dim x, y

???? ???????

????? ???? ?????? ?????? ?? ?? ?? ???? ????? ????? ????? ??????? ?? ?????? ??????? ????? ?? ?? ??????? ??????? ??????? ?? ?? ???????? ??????. ??? ???? ????? ?? ??????? ??????? ???? ??? ??????. ????? ????? ?????? ??? ??? ?????? ??????? ????? ?????? ???????? ?????? ?????? ??????? ??????. ?????? ????? ??? ????? ????? ???? ?????? ??????? ????? ?? ?? ???????.

???? ????? ???????

??? ????? ????? ?? ???? ????? ??????? ???? ??? ??? ????? ???????. ??? ??? ?????? ???? ????? ????? ???? ????? ???????? ?? ??????? ??????? ?? ???? ????? ????? ????? ???????.

?????? ?? ?? ????? ?? ???? ????? ??????? ?????? ???? ??????? ??? ?? ??????? ???? ??????? ???????:
  1. ????? ???? ????? ????? ?? ???????.
  2. ???? ?? ?? ????? ??????? ??????? ?? ??? ?????? ???????:
    Sub Macro1()
    Dim x As Integer
    x = 10
    MsgBox "x, as seen by Macro1 is " & x
    'the next line runs Macro2
    Macro2
    End Sub
    Sub Macro2()
    MsgBox "x, as seen by Macro2 is " & x
    End Sub
    
  3. ????? ????? 1.

    ????? ??????? ???????:
    x? ??? ????? ????? 1 ?? 10
  4. ???? ??? ?????.

    ???? ??????? ???????:
    x? ??? ????? Macro2 ??
  5. ???? ??? ?????.
?? ???? Macro2 ???? ??????? x ??? ??????? x ???? ????? 1.

???? ????? ?????? ??????? ?????? ???????

????? ????? ????????? ?? ???? declarations ?? ???? ????? (?? ????? ?????? ?? ???? ?????? ?????? ?????? ?????????)? ??? ?????? ?????? ????? ?? ??????? ???????? ??????? ?????? ?? ??????? Dim ??????? ?????? . ??? ??? ???? ??????? ?????? ???? ??????? ????? ??? ????? ???? ????? ????? ????? ????? ??????? ?? ???? ??????? ??????? ?? ???????. ??? ??? ???? ??????? Dim ?? ??????? ?????? ???? ??????? ????? ??? ????? ???? ????? ??? ??? ????? ??????? ?? ?????? ??????? ??? ??? ??????.

??????? ????? ??? ??????? ?????? ????????? Dim ? ???? ??????? ???????:
  1. ???? ????? ?? ?????? ?????? ?? ??? ???? ??????.
  2. ??? ????? ???? Visual Basic.
  3. ????? ???? ????? ?? ??????? ????? ??.
  4. ???? ???????? ???????? ??????? ?? ??? ?????? ???????:
    Public x As Integer
    Sub Macro_1a()
    x = 10
    MsgBox x
    Macro_1b
    End Sub
    Sub Macro_1b()
    x = x * 2
    MsgBox x
    Macro2
    End Sub
    
  5. ????? ???? ????? ???? ?? ???????.
  6. ???? ???????? ???????? ??????? ?? ??? ?????? ???????:
    Sub Macro2()
    x = x * 3
    MsgBox x
    End Sub
    
  7. ????? ??????? Macro_1a ?? ?????? ??????? ?????.

    ?? x ????? ?? ??????? "?????? x ??????"? ???? ????? ??????? ??????? ?? ??????? ?? ?????? ??? ???? ? x. ???? ???? ??????? ????? ???? 10. ??????? ??????? ???? ???? ???? 20 (??? ??? ??? x 2 ?? Macro_1b). ???? ???? ??????? ??????? ???? 60 (??? ?????? ?????? x ??? 20 ?? Macro_1b ??? ??? 3 ?? Macro2).
  8. ????? ?? ??????? ?? ?????? ??????? ????? ??:
    Public x As Integer

    ???:
    Dim x As Integer
  9. ????? ??????? Macro_1a .

    ?? x ????? ?? ??????? ? "Dim x As ??? ???? "? ????? ??????? ?? ?????? ??????? ????? ??? ?? ?????? ??? ?????? ? x. ??? ???? ???? ??????? ????? ???? 10? ???? ???? ??????? ??????? ???? 20? (??? ??? ??? x 2 ?? Macro_1b) ????? ???? ??????? ??????? ???? ??? 0 (??? ?? ??? Macro2 ???? x ????? ????? ??? ???? ??? ??????? ?????? ??????? 2).
  10. ????? ?? ??????? ?? ?????? ??????? ????? ??:
    Dim x As Integer

    ???:
    Private x As Integer
  11. ????? ??????? Macro_1a .
??? ??? ?????? ??????? ??? ???????? ???? ?????? ????? ??? ???? ???????? ????? Dim . ??????? x ?? ??? ??????? ???? ?????? ??????? ??? ??? ??????.

?????? ??? ??? ???? ???? ??????? ????? ?? ?? ????? ?????? ??????? ??? ??? ?????? ?????? ??????? ?????? ????? ?? ??????? Dim . ?????? ????? ??????? ????? ???? ??? ?????? ???? ?????? ??? ????? ????????? ???????? ??? ??? ?????? ??????? ?????? .

??? ???? ???????

???? ????? ????? ????? ????? ????? ?????? ?? ??? ??????. ?? ????? ???? ????? ??? ??? ?????? ???? ???????? ?????. ????? ????? ???? ????? ??????? ???? ?? ??? ????.

????? ?????? ??????

????? ???? ?????? ?????? ??? ????? ???? ??????? ????. ??? ????? ????? ????? ??? ???? ????? ?????? ????? ????? ??? ????? ??? ??? ???? ("")? ???? ????? ????? ??? ??? ???? ???????? ????? ASCII 0. ??? ????? ????? ?? ????????? ??? ???? ?????. ????? ??? ????? ??????? ???? ?? ???? ???? ?????? ??? ??? ???? ("") ?? ???? ?????.

????????? ??? ????? ???????

??? ??? ???? ????? ???? ?? ???? ????? ???????? ??????? Dim ? ????? ??????? ????? ????? ?? ??????? ??? ???????. ??? ??? ??? ??????? ???????? ????? ??????? ??????? ???? ??????? ???????? (??? ????? ?????? ??????? ?????? ??) ?? ??? ??? ????? ???? ???? ?????? ????? ???????.

???? ????????? ??? ????? ??????? ??? ?????? ???? ??????? ???????:
  1. ????? ???? ????? ????? ?? ???????.
  2. ???? ?? ?? ????? ??????? ??????? ?? ??? ?????? ???????:
    Sub Macro1()
    'set x as a procedure level variable
    Dim x As Integer
       MsgBox "the initialized value of x is " & x
    x = 10
    MsgBox "x is " & x
    'the next line runs Macro2
    Macro2
    MsgBox "x is still " & x
    End Sub
    Sub Macro2()
    MsgBox "x, as seen by Macro2 is " & x
    End Sub
    
  3. ????? ????? 1.

    ????? ??????? ???????:
    ??? ?????? ????? x ?? 0
  4. ???? ??? ?????.

    ???? ??????? ???????:
    x ?? 10
  5. ???? ??? ?????.

    ???? ??????? ???????:
    x? ??? ????? Macro2
  6. ???? ??? ?????.

    ?? ???? Macro2 ???? ??????? x ??? ??????? x ???? ????? 1. ????? ??????? ???????:
    x ?? ???? 10
  7. ???? ??? ?????.
  8. ????? ????? 1.
????? ????? ??? ??????? ?? ??????? ?? 3 ??? 6 ???? ????? ?????? 1 ????? ????? ?? ?????? 6? ???? ??????? x ?? ?????. ????? ??? ????? ????? ????? 1 ?? ?????? 7? ???? ??? ????? ?????? x ???? ( ????? ??????).

?????? ???????? ?????

??? ?? ??????? ?? ????? ??? ????? ??????? ???????? ???? ?????? ????????? ??????? ????? ????? ??? ??? ????? ????? ??????? ????? ??. ????? ??? ??? ???? ????? ????? ?? ????? ??????? ???? ???? ???????? ????? ????? ??? ??? ????? ??????? ?????? ??? ?????? ??????.

?????? ????? ?????? ???????? ????? works? ???? ??????? ???????:
  1. ????? ????????? ???????? ?? ????? 1 ???:
    Sub Macro1()
    'set x as a procedure level variable
    Static x As Integer
       MsgBox "the initialized value of x is " & x
    x = x + 10
    MsgBox "x is " & x
    End Sub
    
  2. ????? ????? 1.

    ????? ??????? ???????:
    ??? ?????? ????? x ?? 0
  3. ???? ??? ?????.

    ???? ??????? ???????:
    x ?? 10
  4. ???? ??? ?????.
  5. ????? ????? 1.

    ????? ??????? ???????:
    ??? ?????? ????? ? ?? 10
  6. ???? ??? ?????.

    ???? ??????? ???????:
    x ?? 20
  7. ???? ??? ?????.
????? ????? ???? ???? ?? ??????? ?????? ????? ???? ?? ????? ??????? x ?????? ???? ???????? ????? ????? ??? ????? ?????? ????? 1 ????? ???.

?????? ??? ??? ???? ????? ????? ?????? ???????? ??? ?????? ?????? ?? ?? ??? ??? ??? ????? ????? ??????? ?????.

?????? ?? ??? ????? ????? ?????? ???????? ???? ??????? ???????:
  1. ????? ????????? ???????? ?? ?????? ??????? ???? ????? ??? ????? 1 ??? ???:
    Dim x As Integer  'create a module-level variable
    Sub Macro1()
       MsgBox "the initialized value of x is " & x
    x = x + 10
    MsgBox "x is " & x
    End Sub
    
  2. ????? ????? 1.

    ????? ??????? ???????:
    ??? ?????? ????? x ?? 0
  3. ???? ??? ?????.

    ???? ??????? ???????:
    x ?? 10
  4. ???? ??? ?????.
  5. ????? ????? 1.

    ????? ??????? ???????:
    ??? ?????? ????? ? ?? 10
  6. ???? ??? ?????.

    ???? ??????? ???????:
    x ?? 20
  7. ???? ??? ?????.
????? ????? ???? ???? ?? ??????? ?????? ????? ???? ?? ????? ??????? x ?????? ???? ???? ???????? ?? ???? ??? ????? ?????? ????? 1 ????? ???.

????? ????? ????? ?????? ????? ???????

??? ??? ???? ?? ????? ????? ???? ?????? ???? ?? ???? ???? ????? ????? ?????? ??????? ????? ????? ???? ??? ????? ???? ???????? ?? ???? ??? ????? ????? ??? ????? ???????.

??? ??? ???? ?????? ????? 1 ?? ??? ????? ????? 1? ??? ????? ???? ??????? x ??? ???? ??? ??? ???? ???? ??????? ??????:
??? ?????? ????? ? 0
????? ?? ?????????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ????? Microsoft":
843145??? ????????????? Excel ?? Visual Basic ????????? (??????)
?????? ??? ????

???????

???? ???????: 843144 - ????? ??? ??????: 17/????? ??????/1434 - ??????: 5.0
????? ???
  • Microsoft Office Excel 2007
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Excel 97 Standard Edition
????? ??????: 
kbvba kbprogramming kbinfo kbmt KB843144 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????843144

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com