开发者

VBA - Prevent Excel 2007 from showing a defined names message box?

开发者 https://www.devze.com 2022-12-29 00:57 出处:网络
I am working on a Excel 2007 workbook that will contain a macro to save the current sheet (a template) as

I am working on a Excel 2007 workbook that will contain a macro to save the current sheet (a template) as

  1. a PDF file (no problem)
  2. a Excel 97-2003 file (problem)

When saving the Excel file a messagebox appears asking about

"Defined names of formulas in this workbook may display different values when they are recalculated...Do you want Excel to recalculate all formulas when this workbook is opened?".

The user can then select Yes/No and then the file will save.

How do I disable the messagebox from appearing?

The default answer would be 'No'.

My code for saving:

Sub saveAs_97_2003_Workbook(tempFilePath As String, tempFileName As String)
    Dim Destwb As Workbook
    Dim SaveFormat As Long

    'Remember the users setting
    SaveFormat = Application.DefaultSaveFormat
    'Set it to the 97-2003 file format
    开发者_如何学GoApplication.DefaultSaveFormat = 56

    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook
    Destwb.CheckCompatibility = False

    With Destwb
        .SaveAs tempFilePath & tempFileName & ".xls", FileFormat:=56
        .Close SaveChanges:=False
    End With

    'Set DefaultSaveFormat back to the users setting
    Application.DefaultSaveFormat = SaveFormat
End Sub


Try putting this around the With, End With:

Application.DisplayAlerts = False

With Destwb
    ...
End With

Application.DisplayAlerts = True

Should suppress the message, but not sure if it'll default the way you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消