admin管理员组

文章数量:1530518

2024年3月21日发(作者:)

Excel,VBA,VB语法基础介绍

Excel VBA

VB 语法基础 介绍

目标 了解 VB 基本语法规则 可以编写简单的代码

一切从宏开始

录制的宏是由 Sub 定义的子过程 [ Private | Public | Friend] [ Static] Sub name

[( ( arglist ) )]

[ statements ] [ Exit Sub] [ statements ] End Sub

Sub Macro1()

With

.Color = -__

.TintAndShade = 0

End With End Sub

将子过程修改为有返回值的函数

[ Public | Private | Friend] [ Static] Function name

[( ( arglist ) )] [ As type ] [ statements ] [ name

= = expression ] [ Exit Function]

[ statements ] [ name

= = expression ] End Function

‘ 返回指定单元格的字体颜色 Funcion GetFontColor(Target As Range) As Long Dim

lCellColor As Long

If IsNumeric() Then

lCellColor =

End If

GetFontColor = lCellColor End Sub

几何运算函数

‘ 计算圆的面积 Function CircleArea(R As Double) As Double Const PI As Double =

3.__979

CircleArea = PI * R ^ 2 End Function

本文标签: 语法过程基础介绍返回值