CRITICAL_ERROR 65535

时间:2017-03-30 21:59:38

标签: excel vba excel-vba

我有一个简单的VBA例程,我以前用过但似乎继续返回Critical_Error 65535 ..这是我的例程..在保存部分的帖子失败,生成值只有excel文件..指针好吗?

Sub SaveFile()
'Recalc Sheets prior to saving down

a = MsgBox("Do you want to Save down todays Consultant Performance Report ?", vbOKCancel)
If a = 2 Then Exit Sub

Dim SaveSheets As Variant
Dim strFilename As String
Dim sheetListRange As Range
Dim sheetName As Variant
Dim wksheet As Variant

Dim wkbSrc As Workbook
Dim wkbNew As Workbook
Dim wksNew As Worksheet
Dim wksSrc As Worksheet
Dim i As Integer

  On Error GoTo ErrorHandler


  strFilename = Worksheets("Control").Range("SavePath").Value & "DailyReport_" & Format$(Now(), "YYYYMMDD") & ".xls"


  Set sheetListRange = Worksheets("Control").Range("SaveList")
  Set wkbSrc = ActiveWorkbook
  Set wkbNew = Workbooks.Add
  i = 0

  For Each sheetName In sheetListRange
    If sheetName = "" Then GoTo NEXT_SHEET
    For Each wksheet In wkbSrc.Sheets
      If wksheet.Name = sheetName Then
        i = i + 1
        wksheet.Copy Before:=wkbNew.Sheets(i)
        Set wksNew = ActiveSheet
        With wksNew
          .Cells.Select
          .Cells.Copy
          .Cells(1, 1).PasteSpecial Paste:=xlPasteValues
          .Cells(1, 1).PasteSpecial Paste:=xlPasteFormats
        End With
        ActiveWindow.Zoom = 75
        GoTo NEXT_SHEET
      End If
    Next wksheet
NEXT_SHEET:
  Next sheetName

  Application.DisplayAlerts = False
  'dont need the default new sheets created by created a new workbook
  wkbNew.Worksheets("Sheet1").Delete
  wkbNew.Worksheets("Sheet2").Delete
  wkbNew.Worksheets("Sheet3").Delete

  ActiveWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlWorkbookNormal
  ActiveWorkbook.Close
  Application.DisplayAlerts = True
  Exit Sub
ErrorHandler:

    'If there is an unknown runtime error give the user the error number and associated description
    '(Description is already set if the erorr is G_LNG_CRITICAL_ERROR)
    If Err.Number <> CRITICAL_ERROR Then Err.Description = "Run-time error " & Err.Number & ": " & Err.Description

    Err.Description = "Error saving worksheet as file: " & Err.Description

    'Raise the error up to the error handler above
    Err.Raise Number:=CRITICAL_ERROR

End Sub

0 个答案:

没有答案