excel 工作簿,关闭提示“想要保存”对话框,即使我关闭了displayalerts

hs1ihplo  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(81)

我的代码提示我想保存更改对话框,即使我有适当的控制到位...会出什么问题呢我用的是Windows 10。

Application.DisplayAlerts = False
TempWB.saved = True
TempWB.close SaveChanges:=False
Application.DisplayAlerts = True
yyyllmsg

yyyllmsg1#

我得到了同样的问题,它奇怪地开始发生上周没有改变我的代码无论如何。
下面是我的全部功能。标准范围转换为HTML,并添加了保存覆盖:

Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2013
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook

    TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With

    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With

    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.readall
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")

    'Close TempWB
    Application.DisplayAlerts = False
    TempWB.Saved = True
    TempWB.Close savechanges:=False
    Application.DisplayAlerts = True

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWb = Nothing

相关问题