欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Excel VBA

程序员文章站 2022-05-14 22:58:12
...

VBA Course: Selections

Selections

Sub Selection()
Cells(8, 1).Select
Sheets("Sheet2").Activate
Range("A1,B4").Select
End Sub

Properties

Sub properties()
    ' 赋值操作 
    Range("A8").Value = 48
    Workbooks("Book2.xlsx").Sheets("Sheet2").Range("A8").Value = "Sample text"
    ' 删除文本内容
    Range("A:A").ClearContents
    ' 设置字符大小
    Range("A1:A8").Font.Size = 18
    ' 字体加粗
    Range("A1:A8").Font.Bold = True
    ' 字体名称
    Range("A1:A8").Font.Name = "Arial"
End Sub

使用with

Sub properties()
	With ActiveCell
		.Border.Weight = 3
		.Font.Bold = True
		.Font.Size = 18
		.Font.Italic = True	'设置斜体
		.Font.Name = "Arial"
	End With
End Sub
Sub properties()
	with ActiveCell
		.Borders.Weight = 3
		With .Font
			.Bold = True
			.Size = 18
			.Italic = True
			.Name = "Arial"
		End With
	End With
End Sub
相关标签: vbnet excel