Sub Macro1() On Error GoTo ErrorHandler Dim sum As Double Dim rng As Range Set rng = Range("A1:A10") sum = Application.WorksheetFunction.Sum(rng) Range("A1").Value = sum Exit Sub ErrorHandler: MsgBox "错误代码:" & Err.Number & vbCrLf & "错误信息:" & Err.Description End Sub ``...
wb.Excel4MacroSheets(1).Visible = xlSheetVeryHidden End Sub Private Function WorkbookOpen(WorkBookName As String) As Boolean WorkbookOpen = False On Error GoTo WorkBookNotOpen If Len(Application.Workbooks(WorkBookName).Name) > 0 Then WorkbookOpen = True Exit Function End If WorkBookNotOpen: End...
Sub 新建表格()On Error GoTo notable Dim aim As Worksheet Dim i, num As Integer Application.ScreenUpdating = False Set aim = Sheets("样表")num = InputBox("请输入要创建的工作表的个数")For i = 1 To num aim.Copy before:=Worksheets(1)Next i Application.DisplayAlerts = False ...
for i=1 to worksheets.count '遍历所有工作表 sheets(i).unprotect "xxx" 'xxx=你的密码,解除保护 。。。你原来的代码 sheets(i).protect "xxx" '重新保护工作表 next i
(59) Application.OnKey “^I”,”macro” ‘设置Ctrl+I键为macro过程的快捷键 (60) Application.CutCopyMode=False ‘退出剪切/复制模式 (61) Application.Volatile True ‘无论何时工作表中任意单元格重新计算,都会强制计算该函数 (62) Application.Volatile False ‘只有在该函数的一个或多个参数发生改变时,才会...
(3) On Error Resume Next 解释:忽略错误继续执行VBA代码,避免出现错误消息 (4) On Error GoTo 100 解释:当错误发生时跳转到过程中的某个位置 (5) On Error GoTo 0 解释:恢复正常的错误提示 (6) Application.DisplayAlerts=False 解释:在程序执行过程中使出现的警告框不显示 (7) Application.DisplayAlerts=Tr...
ThisWorkbook.Path ' 获取工作簿的完整路径和文件名 Dim fullPath As String fullPath = ThisWorkbook.FullName ' 判断工作簿是否已打开(更健壮的函数) Function IsWorkbookOpen(wbName As String) As Boolean On Error Resume Next IsWorkbookOpen = Not (Workbooks(wbName) Is Nothing) On Error GoTo 0 End ...
Sub SafeMacro() On Error GoTo ErrorHandler ' 正常宏代码 ExitSub: Exit Sub ErrorHandler: MsgBox "发生错误: " & Err.Description Resume ExitSub End Sub 恢复工作簿: Excel崩溃后,可以尝试从自动恢复文件中恢复工作簿。 自动恢复文件通常保存在%temp%目录下,文件名以_AutoRecover结尾。
(59) Application.OnKey “^I”,”macro” '设置Ctrl+I键为macro过程的快捷键 (60) Application.CutCopyMode=False ‘退出剪切/复制模式 (61) Application.Volatile True '无论何时工作表中任意单元格重新计算,都会强制计算该函数 (62) Application.Volatile False '只有在该函数的一个或多个参数发生改变时,才会重...
(59) Application.OnKey “^I”,”macro” '设置Ctrl+I键为macro过程的快捷键 (60) Application.CutCopyMode=False ‘退出剪切/复制模式 (61) Application.Volatile True '无论何时工作表中任意单元格重新计算,都会强制计算该函数 (62) Application.Volatile False '只有在该函数的一个或多个参数发生改变时,才会重...