EXCEL-VBA常用代码集.doc
《EXCEL-VBA常用代码集.doc》由会员分享,可在线阅读,更多相关《EXCEL-VBA常用代码集.doc(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateEXCEL-VBA常用代码集EXCEL-VBA常用代码集EXCEL VBA常用代码集1.显示活动工作簿名称MsgBox 当前活动工作簿是 & ActiveWorkbook.Name2.保存活动工作簿Activeworkbook.Save3.保存所有打开的工作簿关闭EXCELFor Each W in Application.WorkbooksW.SaveNext WA
2、pplication.Quit4.将网格线设置为蓝色ActiveWindow.GridlineColorIndex = 55.将工作表sheet1隐藏Sheet1.Visible = xlSheetVeryHidden6.将工作表Shtte1显示Sheet1.Visible = xlSheetVisible7.单击某单元格,该单元格所在的行以蓝色背景填充,字体颜色为白色Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) If Target.Row = 2 Then第二行以下的区域 On Error Resume
3、Next ChangColor_With1.FormatConditions.Delete Target.EntireRow.Name = ChangColor_With1 With ChangColor_With1.FormatConditions .Delete .Add xlExpression, , TRUE .Item(1).Interior.ColorIndex = 5 .Item(1).Font.ColorIndex = 2 End With End IfEnd Sub8.使窗体在启动的时候自动最大化Private Sub UserForm_Initialize() Applic
4、ation.WindowState = xlMaximized With Application Me.Top = .Top Me.Left = .Left Me.Height = .Height Me.Width = .Width End WithEnd Sub9.不保存工作簿退出EXCELApplication.DisplayAlerts = FalseApplication.Quit10.使窗体的关闭按纽不好用Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)If CloseMode = vbf
5、ormcontrdmenu ThenMsgBox 请用关闭按钮关闭窗口!, 64, 提示Cancel = TrueEnd IfEnd Sub11.使窗体在3秒后自动关闭Private Sub UserForm_Activate()Application.Wait Now + TimeValue(00:00:03)UserForm1.HideEnd Sub12.启动窗体的时候自动使Label1显示Sheet1工作表3列,8行的内容Private Sub UserForm_Activate()Label1.Caption = Sheets(sheet1).Cells(3, 8)End Sub13.
6、让按纽CommandButton1在窗体上以不可用状态显示CommandButton1.Enabled = False14.让按纽Commandbutton1在窗体上以隐藏方式存在CommandButton10.Visible = False15.点击Commandbutton1按纽进入”工资”工作表Sheets(工资).Select16.在Textbox1中输入数据,窗体可显示出”工资”工作表中与输入内容关联的项Private Sub TextBox1_Change() For X = 1 To Application.CountA(Sheets(工资).Range(a:a)If Sheet
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- EXCEL VBA 常用 代码
限制150内