VBA设置单元格的格式之代码
Admin | 2010-4-18 20:56:54 | 被阅次数 | 27460
以下代码功能是,通过VBA设置单元格的格式,以下示例为设置单元格格式为普通文本。
希望本文对您有所帮助。
Dim ExcelBook As Excel.Workbook
Dim Esheets As Sheets
Dim Esheet As Excel.Worksheet
Dim strFilePath As String
strFilePath = "E:\我的工作薄.xls"
If Dir(strFilePath, vbNormal) = "" Then
Exit Sub
End If
Set ExcelBook = GetObject(strFilePath)
Set Esheets = ExcelBook.Sheets
If Esheets.Count = 0 Then Exit Sub
ExcelBook.Activate
Set Esheet = Esheets(1)
Esheet.Activate
'设置B列的单元格的格式为文本
Esheet.Range("B:B").NumberFormatLocal = "@"
Esheet.Cells(1, 1) = "00001"
ExcelBook.Save
ExcelBook.Close
Set ExcelBook = Nothing
Set Esheets = Nothing
Set Esheet = Nothing