循环语句:
do loop 语句while和until即可放在do 后面也可放在while后面
for next 语句 1.to step分句2.each in分句
while wend 语句
with end with 语句
goto 语句
声明变量、数组:
Dim 变量 as 类型 '定义为局部变量,如 Dim xyz as integer
Private 变量 as 类型 '定义为私有变量,如 Private xyz as byte
Public 变量 as 类型 '定义为公有变量,如 Public xyz as single
Global 变量 as 类型 '定义为全局变量,如 Globlal xyz as date
Static 变量 as 类型 '定义为静态变量,如 Static xyz as double
Dim aaa(9) as integer
dim arr(1 to 10)
dim arr() redim arr(1 to 10 ) redim preserve arr(1 to 20)
赋值语句
普通变量赋值语句let 对象变量赋值语句set
Sub Clear_pics()
Dim Shp As Shape
For Each Shp In ActiveSheet.Shapes
If Shp.Type = msoPicture/= msoFormControl/<>8 Then Shp.Delete
Next
End Sub
dir(i)
ActiveSheet.Shapes.AddShape(i,true,true, Range("a1").Left, Range("a1").Top, Range("a1").Width, Range("a1").Height)
ActiveDocument.Tables(1).Cell(3, 1).InlineShapes.AddPicture FileName:="C:\a.jpg", LinkToFile:=True, SaveWithDocument:=True
ActiveSheet.Pictures(Mytext).Delete '删除单元格中原来的图片
picPath = ThisWorkbook.Path & "\" & Mytext & ".jpg" '定义插入图片的地址
MsgBox picPath
Set pictemp = ActiveSheet.Pictures.Insert(picPath) '插入图片
pictemp.Name = Mytext '设定所插入图片的名称
pictemp.Placement = xlMoveAndSize '设置图片可以随单元格的变动而改变大小和位置
With pictemp.ShapeRange
.LockAspectRatio = msoFalse '取消图片纵横比锁定
.Height = Selection.Height '设置所插入图片的高度与单元格的高度相等
.Width = Selection.Width '设置所插入图片的宽度与单元格的宽度相等
End With
Set pictemp = Nothing '重置图片对象
.定位
VBA中,通过名称选中:sheets("sheet1") 'sheet1表示工作表的名称
VBA中,通过索引选中:sheets(1) '1代表第一个工作表
Dim i As Integer, str As String
For i = 1 To Workbooks.Count
str = Workbooks(i).Name
If str Like "*.csv" Then
Workbooks(i).Activate
End If
Next i
word文档.Tables(1).Cell(1, 2).Range.Text
.