QINMS.com >> 首页 >>  >> 正文

EXCEL-VBA代码(三)

12.修改状态栏:

Application.StatusBar = "今天是:" & Year(Now()) & "年" & Month(Now()) & "月" & Day(Now()) & "日"

13.功能区

功能区隐藏:

Sub HideRibbon()

     Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"

End Sub

重新显示:

Sub ShowRibbon()

    Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"

End Sub

14.查询是否为数字:

Private Sub Button_Click()

Dim i As Variant

i = InputBox("请输入一个数字", "数字录入中", 1)

If IsNumeric(i) = False Then

  MsgBox "你输入的不是数值,请重新输入", , "输入错误!"

  i = InputBox("请输入一个数字", "数字录入中", 1)

End If

End Sub

15.创建TXT文件

Sub TextStreamTest()

Dim a As String

a = "wwww" & Chr(10) & "eeee"

Dim fso, MyFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set MyFile = fso.CreateTextFile("g:\aaa.txt", True)

MyFile.WriteLine (a)

MyFile.close

Set fso = Nothing

Set MyFile = Nothing

End Sub

16.锁定工作表:

Private Sub Workbook_Open()

Sheet1.Select

Sheet1.ScrollArea = "A1"

End Sub

  '式中"A1"为显示的左上角格(可编辑)/可按需更改(如:"C10:j30")

上一页1】【2】[3]

METi. 版权所有 |