Function GetVitals(ID As Long, Age As Long, Optional Weight As Long) As String GetVitals = "ID=" & ID & "Age=" & Age & "Weight=" & Weight End Function Sub ShowVitals() Dim ID As Long, Age As Long, Weight As Long Debug.Print GetVitals(ID:=5, Age:=20) Debug.Print GetVitals(ID:=6, Age:=25, Weight:=130) End Sub
ID=5 Age = 20 Weight=
ID=6 Age = 25 Weight=130
ID=5 Age = 20 Weight=0
ID=6 Age = 25 Weight=130
ID=5 Age = 20 Weight=Null
ID=6 Age = 25 Weight=130
ID=5 Age = 20
ID=6 Age = 25 Weight=130
Sub CalledSub(Surname, Age)
Sub MySub(VarA As Long, ParamArray VarB() As Variant) MsgBox VarB(0) End Sub Sub ShowValue() Call MySub(10, "First arg", 2, 3.1416) End Sub
Sub UseSum() Dim TestArray() As Integer, Total As Integer ReDim TestArray(1) TestArray(1) = 6 ReDim TestArray(2) TestArray(2) = 3 Total = WorksheetFunction.Sum(TestArray) End Sub
Function SquareIt(ByRef Basis As Integer) As Long SquareIt = Basis ^ 2 End Function
Dim Result As Long, Side As Integer Side = 5 Result = Squarelt(Side) End Sub
Dim Result As Long, Side Side = 5 Result = SquareIt(Cint(Side)) End Sub
Range("E3:312").Range("B3").Select
_MyVar
My_Var
My-Var
1MyVar
在命名Visual Basic模块中的过程、常量、变量和参数时,请使用以下规则:必须使用字母作为第一个字符。不能使用空格、句点(.)、感叹号(!)或字符 @、&、$、#在名称中。名称的长度不能超过255个字符。
Type CBC Name As String Next As String End Type
Type CBC Name As String _Next As String End Type
Type CBC Name As String @Option As String End Type
Type CBC Name As String %For As String End Type
单击窗体,然后选择“复制”。 3. 切换到另一个项目。 4. 右键单击模块,然后选择“粘贴”。
Option Base 0
Sub BuildArray()
Dim MyArray(5) As Integer
Enum TestEnum Test1 Test2 Test3 End Enum
窗体?
Dim MyVar As String
Sub AAA()
Dim MyVar As String
MyVar = "Procedure AAA Scope"
End Sub
Sub BBB()
MyVar = "Procedure BBB Scope"
End Sub
Here are the questions converted:
Public Property Get HDL() As Double HDL = pHDL End Property Public Property Let HDL(Value As Double) pHDL = Value End Property
Property Get HDL() As Double HDL = Value End Property Property Let HDL(Value As Double) pHDL = Value End Property
Public Property Get HDL() As Double HDL = Value End Property Public Property Let HDL(Value As Double) pHDL = Value End Property
Public Property Get HDL() As Single HDL = pHDL End Property Public Property Let HDL(Value As Double) pHDL = Value End Property
Sub MakeErrors() Dim Y As Variant, Z As Variant On Error Resume Next Y = 1 / 0 MsgBox "Y = " & Y On Error GoTo 0 Z - (0 - 3) ^ 0.5 MsgBox "Z = " & Z End Sub
Private Sub CommandButton1_Click() If FoundErrors(Me) Then _ Me.Show End Sub
Private Sub CommandButton1_Click() If Not FoundErrors(UserForm1) Then _ Unload UserForm1 End Sub
Private Sub CommandButton1_Click() Me.Hide Do While FoundErrors(Me) Me.Show Loop End Sub
Private Sub CommandButton1_Click() Do While FoundErrors(UserForm1) UserForm1.show Loop End Sub
第一个要求是使UserForm1加载但不可见,因此我们需要Me.Hide,这里的Me指的是UserForm1。
With Selection
&TypeText Text:="8/24/2019"
&TypeParagraph
&TypeText Text:="1161 Alamosa Drive"
End With
With Selection
.TypeText Text:="8/24/2019"
.TypeParagraph
.TypeText Text:="1161 Alamosa Drive"
End With
With Selection
TypeText Text:="8/24/2019"
TypeParagraph
TypeText Text:="1161 Alamosa Drive"
End With
With Selection:
&TypeText Text:="8/24/2019"
&TypeParagraph
&TypeText Text:="1161 Alamosa Drive"
End With
Sub Example() Dim MyArr() As Variant ReDim MyArr(3, 4) 'some code ReDim Preserve MyArr(4, 4) End Sub
ReDim Preserve MyArr(0 To 4, 0 To 4)
。 Sub Called(Salary As Long, ParamArray Vals() As Variant)
Sub Called(ParamArray Vals() As Variant, Salary As Long)
Sub Called(Optional Salary As Long, ParamArray Vals() As Variant)
Sub Called(Salary As Long, ParamArray Vals() As String)
UserForm1.Show vbModal
SpecialEffect
属性设置为frmShowModal
UserForm1.Hwnd = False
ShowModal
属性设置为False Sub SubB(ByRef MyVar)
Sub SubB(MyVar)
Sub SubB(Static MyVar)
Sub SubB(ByVal MyVar)
Sub MySub(VarA As String, Optional VarB _ As Variant, Optional VarC As Long)
Sub MySub(VarA As String, Optional VarB _ As Variant, VarC As Long)
Sub MySub(Optional VarA As String, Optional VarB _ As Variant, VarC as Long)
Sub MySub(OPtional VarA As String, VarB _ As Variant, Optional VarC as Long)
Sub Decs() Dim MyFixed As String * 0 MyFixed = "A" MsgBox MyFixed End Sub
Sub Decs() Dim MyInt% * 1 MyInt = 7 MsgBox MyInt End Sub
Sub Decs() Dim MyInt% As Integer * 1 MyInt = 5 MsgBox MyInt End Sub
Sub Decs() Dim MyInt, MyNum As Integer MyInt = "A" MsgBox MyInt End Sub
= CountValues= CountValues
| CountValues| CountValues
: CountValues: CountValues
? CountValues? CountValues
Private TopSecret As String
?UserForm1.Show vbModal
SpecialEffect
属性设置为frmShowModal
UserForm1.Hwnd = False
ShowModal
属性设置为False Sub SubB(Static MyVar)
Sub SubB(ByVal MyVar)
Sub SubB(MyVar)
Sub SubB(ByRef MyVar)
Sub Example() Dim MyArr() As Variant ReDim MyArr(3, 4) 'some code ReDim Preserve MyArr(4, 4) End Sub Sub Example() Dim MyArr() As Variant ReDim MyArr(3, 4) 'some code ReDim Preserve MyArr(4, 4) End Sub
ReDim Preserve MyArr(0 To 4, 0 To 4)
。 Sub SubB(ByRef MyVar)
。 Do X = X + 1 i = i + 1 Loop Until i < 5 End Sub
Sub Loopi() Dim X As Integer, i As Integer For i = 1 To 5 X = X + 1 Next I End Sub
Sub Loopi() Dim X As Integer, i As Integer Do Until i < 5 X = X + 1 i = i + 1 Loop End Sub
Sub Loopi() Dim X As Integer, i As Integer Do X = X + 1 i = i + 1 Loop While i < 5 End Sub
Sub Sumosts(AcctName As String, Amount As Long) Range("A1") = AcctName End Sub
If Cars(1).Make="Ford" And Cars (1).MPG > 20
Then Cars(1).Selected = True
ActiveCell.Offset(3,4).Range("A1:E5").Select
Range("b3:f5, c4:d9").Select
Range("b3:f5", "c4:d9").Select
If Cars(1).Make="Ford" And Cars (1).MPG > 20
Then Cars(1).Selected = True
ActiveCell.Offset(3,4).Range("A1:E5").Select
Range("b3:f5, c4:d9").Select
Range("b3:f5", "c4:d9").Select