功能语法第1章 Application 对象
当前操作系统的名称和版本号Application.OperatingSystem
当前的注册组织名Application.OrganizationName
计算机名Environ("computername")
当前用户名Application.UserName
Environ("Username")
启动微软的应用程序Application.ActivateMicrosoftApp x
x为:
xlMicrosoftWord
xlMicrosoftPowerPoint
xlMicrosoftMail
xlMicrosoftAccess
xlMicrosoftFoxPro
xlMicrosoftProject
xlMicrosoftSchedulePlus
当前剩余内存Application.MemoryFree
当前Microsoft Excel的总内存Application.MemoryTotal
被Excel使用的内存Application.MemoryUsed
Excel 版本Application.Version
Excel 安装路径Application.Path
启动Excel的路径Application.StartupPath
打开Excel文件时使用的默认路径Application.DefaultFilePath
模板保存的默认路径Application.TemplatesPath
库文件夹的路径Application.LibraryPath
路径分隔符Application.PathSeparator
设置文件清单中的最多文件数Application.RecentFiles.Maximum = n 设置新工作簿中的工作表个数Application.SheetsInNewWorkbook = n 设置文件的默认位置Application.DefaultFilePath = "路径"打开Excel帮助文件Application.Help
Excel全屏显示Application.DisplayFullScreen = True
Application.DisplayFullScreen = False
Excel窗口显示Application.WindowState = x
x为:
xlMaximized
xlMinimized
xlNormal
Excel窗口位置Application.Height
Application.Width
Application.Left
Application.Top
在主窗口中所能占有的最大高度和宽度Application.UsableHeight
Application.UsableWidth
隐藏显示Excel Application.Visible = False\True
Excel标题设置Application.Caption = "***"
Application.Caption = vbNullString
Application.Caption = vbNullChar
设置状态栏中的文字Application.StatusBar = "***"
Application.StatusBar = False
隐藏显示状态栏Application.DisplayStatusBar = False\True
隐藏显示编辑栏Application.DisplayFormulaBar = False\True
隐藏显示常用工具栏Application.CommandBars("Standard").Visible = False\True 隐藏显示格式工具栏Application.CommandBars("Formatting").Visible = False\True 隐藏显示任务窗格Application.CommandBars("Task Pane").Visible = False\True
更改鼠标指针形状Application.Cursor = x
x为:
xlWait
xlIBeam
xlNorthwestArrow
xlDefault
撤消上次操作Application.Undo
自动手动计算Application.Calculation = x
x为:
xlCalculationAutomatic
xlCalculationManual
xlCalculationSemiautomatic
切换引用样式Application.ReferenceStyle = xlA1
Application.ReferenceStyle = xlR1C1
按回车切换单元格移动方向Application.MoveAfterReturn = True
Application.MoveAfterReturnDirection = x
x为:
xlToRight
xlDown
xlToLeft
xlUp
禁用Ctrl+Break中止宏运行的功能Application.Enable.CancelKey=xlDisabled
禁止在单元格中直接编辑Application.EditDirectlyInCell = False\True
屏幕刷新Application.ScreenUpdating = False\True
指定对象禁用启用事件Application.EnableEvents = False\True
禁用启用Esc键捕获功能Application.EnableCancelKey = xlDisabled
Application.EnableCancelKey = xlInterrupt
关闭显示警告信息框Application.DisplayAlerts = False\True
清空剪贴板Application.CutCopyMode = False\True
安装指定加载宏Application.AddIns("加载宏名").Installed = True
打开内置对话框Application.Dialogs(n).Show
值n为:
1 xlDialogOpen
5 xlDialogSaveAs
7 xlDialogPageSetup
8 xlDialogPrint
9 xlDialogPrinterSetup
17 xlDialogRun
23 xlDialogSetPrintTitles
26 xlDialogFont
27 xlDialogDisplay
41 xlDialogTable
42 xlDialogFormatNumber
45 xlDialogBorder
46 xlDialogCellProtection
47 xlDialogColumnWidth
52 xlDialogClear
55 xlDialogInsert
61 xlDialogDefineName
84 xlDialogPatterns
111 xlDialogDeleteFormat
119 xlDialogNew
127 xlDialogRowHeight
189 xlDialogSendMail
222 xlDialogPrintPreview
229 xlDialogDefineStyle
282 xlDialogWorkbookMove
283 xlDialogWorkbookCopy
302 xlDialogWorkbookNew
342 xlDialogInsertPicture
354 xlDialogWorkbookInsert
386 xlDialogWorkbookName
417 xlDialogWorkbookProtect
476 xlDialogActiveCellFont
509 xlDialogSetBackgroundPicture
583 xlDialogConditionalFormatting
596 xlDialogInsertHyperlink
用户输入的对话框Selection.Value = Application.InputBox(Prompt:=myPrompt, Title:=myTitle, Type:=0)
Selection.Value = Application.InputBox(Prompt:=myPrompt, Title:=myTitle, Type:=1)
Selection.Value = Application.InputBox(Prompt:=myPrompt, Title:=myTitle, Type:=2)
Application.InputBox( Prompt:=myPrompt, Title:=myTitle, Default:=myDefault, Type:=8)
Application.InputBox(Prompt:=myPrompt, Title:=myTitle, Type:=1 + 2)
Application.InputBox(Prompt:=myPrompt, Title:=myTitle, Default:=myDefault, Type:=2)
显示消息对话框  a = MsgBox("信息",x1 + x2 + x3 + x4 ,"标题")
x1为:
0/vbOKOnly
1/VbOKCancel
2/VbAbortRetryIgnore
3/VbYesNoCancel
4/VbYesNo
5/VbRetryCancel
x2为:
16/VbCritical
32/VbQuestion
48/VbExclamation
64/VbInformation
x3为:
0/vbDefaultButton1
256/vbDefaultButton2
512/vbDefaultButton3
768/vbDefaultButton4
x4为:
16384/vbMsgBoxHelpButton
524288/vbMsgBoxRight
a返回为:
1/vbOK
2/vbCancel
3/vbAbort
4/vbRetry
5/vbIgnore
6/vbYes
7/vbNo
运行宏Application.Run "宏名"
一段时间后运行宏Application.OnTime Now + TimeValue("00:00:05"), "宏名"
某时间运行宏Application.OnTime TimeValue("0:00:00"), "宏名"
制定宏运行的时间计划Application.OnTime EarliestTime:=NextTime, Procedure:="宏名"
取消运行计划Application.OnTime EarliestTime:=TimeValue("00:00:00"), Procedure:="宏名", Schedule:=False 退出 Excel Application.Quit
第2章 Wordbook(工作簿)对象
工作簿名Workbooks(1).Name
当前活动工作簿名ActiveWorkbook.Name
ThisWorkbook.Name
当前完整路径的工作簿名ThisWorkbook.FullName
本工作簿的基本名称Left(ThisWorkbook.Name, InStr(ThisWorkbook.Name, ".") - 1)
工作簿路径Workbooks("工作簿").Path
当前活动工作簿的路径ActiveWorkbook.Path
ThisWorkbook.Path
新建工作簿Workbooks.Add
打开工作簿Workbooks.Open Filename:="路径",UpdateLinks:=x
x为:
1
2
3
打开工作簿(窗口选择)Workbooks.Open Filename:=Application.GetOpenFilename("Excel工作簿(*.xls),*.xls")工作簿是否打开Not Application.Workbooks("工作簿名") Is Nothing = True
工作簿打开方式Workbooks(1).ReadOnly = True
Workbooks(1).ReadOnly = False
打开的工作簿数Workbooks.Count
打开最近使用过的文件Application.RecentFiles(n).Open
保存工作簿Workbooks("工作簿").Save
另存工作簿并设密码ThisWorkbook.SaveAs Filename:="路径", WriteResPassword:="密码"
另存工作簿(窗口选择)ThisWorkbook.SaveAs Filename:=Application.GetSaveAsFilename(, "Excel工作簿(*.xls),*.xls")指定工作簿的副本保存到文件ThisWorkbook.SaveCopyAs Filename:="路径"
保存自动恢复文件With Application.AutoRecover
.Time = 分钟
.Path = "路径"
End With
当前工作薄文件添加到收藏中ActiveWorkbook.AddToFavorites
工作簿是否保存Workbooks("工作簿名").Saved = True/False
工作簿最后保存时间Workbooks("工作簿名").BuiltinDocumentProperties("Last Save Time")关闭工作簿ThisWorkbook.Close savechanges:=False
关闭所以工作簿Workbooks.Close
保护撤消工作薄Workbooks(1).Protect Password:="***", Structure:=True, Windows:=True
Workbooks(1).Unprotect Password:="***"
窗格冻结ActiveWindow.FreezePanes=True/False
结构窗口保护Workbooks(1).ProtectStructure = True
Workbooks(1).ProtectWindows = True
窗口的标题ActiveWindow.Caption
Windows(1).Caption
Application.Windows(1).Caption
窗口拆分ActiveWindow.Split=True/False
ActiveWindow.SplitColumn = 1
ActiveWindow.SplitRow = 1
ActiveWindow.SplitHorizontal
ActiveWindow.SplitVertical
窗口切换ActiveWindow.ActivateNext
ActiveWindow.ActivatePrevious
窗口隐藏ActiveWindow..Visible = False/True
pane新建窗口ActiveWindow.NewWindow
Windows.Arrange Arrangestyle:=xlArrangeStyleVertical
ActiveWindow.WindowState = xlMaximized
重排窗口Windows.Arrange ActiveWorkbook:=True
Windows.Arrange Arrangestyle:= x
x为:
xlArrangeStyleTiled
xlArrangeStyleCascade
xlArrangeStyleHorizontal
xlArrangeStyleVertical
显示比例ActiveWindow.Zoom = 200
ActiveWindow.Zoom = 100
设置工作簿视图选项ActiveWindow.DisplayFormulas = False

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。