gpt4 book ai didi

excel - "Application.DisplayAlerts = False"Excel崩溃

转载 作者:行者123 更新时间:2023-12-04 21:16:05 24 4
gpt4 key购买 nike

我的代码可以打开四个工作簿,重新格式化数据,将其粘贴到当前工作簿中,然后关闭其他工作簿。

当我关闭其他工作簿时,我会收到一个 DisplayAlert,询问我是否要保存工作簿。我想停止出现 DisplayAlert。

微软推荐:

Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

当我这样做时,Excel 崩溃了。

代码:
Function rngFoundLog(searchDate As Date)

Set rngSearchLog = Workbooks("Ecom KPI.xlsm").Worksheets("Daily Update Log").Range("A:A")
Set rngFoundLog = rngSearchLog.Find(What:=Sheet1.searchDate, LookIn:=xlValues, LookAt:=xlPart)

End Function

Function formatHourlies(fileName As String) As Object

Dim fullFileName As String
fullFileName = ActiveWorkbook.Path & "\Hourlies\" + fileName
Workbooks.Open fileName:=fullFileName

Workbooks(fileName).Worksheets("Top Line Metrics").Range("B9:H32").Copy
Workbooks(fileName).Worksheets("Top Line Metrics").Range("A34").PasteSpecial Transpose:=True

Workbooks(fileName).Worksheets("Top Line Metrics_0").Range("B9:H32").Copy
Workbooks(fileName).Worksheets("Top Line Metrics").Range("Y34").PasteSpecial Transpose:=True

Workbooks(fileName).Worksheets("Top Line Metrics_1").Range("N9:H32").Copy
Workbooks(fileName).Worksheets("Top Line Metrics").Range("AW34").PasteSpecial Transpose:=True

Workbooks(fileName).Worksheets("Top Line Metrics").Range("A34:BT40").Select
Selection.Replace What:="-", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Selection.Copy

End Function

Sub HourlyData()

Application.Calculation = xlManual
Application.ScreenUpdating = False
'Application.DisplayAlerts = False

Dim proxyServer As String
Dim clientID As String
Dim report_period As String
Dim report_date As String
Dim searchDate As Date

Sheet1.proxyServer = Worksheets("Update Data").Range("H2").Value
Sheet1.proxyStatus = Worksheets("Update Data").Range("H1").Value
Sheet1.report_date = Worksheets("Update Data").Range("B2").Value
Sheet1.searchDate = Worksheets("Update Data").Range("B3").Value

Dim answer As Integer
answer = MsgBox("Do you want to import the data?", vbYesNo + vbQuestion, "Import Data?")
If answer = vbYes Then

Dim StartTime As Double
Dim MinutesElapsed As String
Dim dateRange As Range
StartTime = Timer

reportDate = Worksheets("Update Data").Range("B3").Value
searchDatev2 = reportDate - 7

Set rngSearch = Worksheets("Business Objects").Range("A:A")
Set rngFound = rngSearch.Find(What:=searchDatev2, LookIn:=xlValues, LookAt:=xlPart)

Dim fileName As String
fileName = "couk Hourlies.xlsx"
formatHourlies (fileName)
Workbooks("Ecom KPI.xlsm").Worksheets("Hourlies").Range("B" & rngFound.Row).PasteSpecial xlPasteValues
Workbooks(fileName).Close

fileName = "mcouk Hourlies.xlsx"
formatHourlies (fileName)
Workbooks("Ecom KPI.xlsm").Worksheets("Hourlies").Range("EQ" & rngFound.Row).PasteSpecial xlPasteValues
Workbooks(fileName).Close

fileName = "ie Hourlies.xlsx"
formatHourlies (fileName)
Workbooks("Ecom KPI.xlsm").Worksheets("Hourlies").Range("KF" & rngFound.Row).PasteSpecial xlPasteValues
Workbooks(fileName).Close

fileName = "mie Hourlies.xlsx"
formatHourlies (fileName)
Workbooks("Ecom KPI.xlsm").Worksheets("Hourlies").Range("PU" & rngFound.Row).PasteSpecial xlPasteValues
Workbooks(fileName).Close

Workbooks("Ecom KPI.xlsm").Worksheets("Daily Update Log").Range("T" & rngFoundLog(Sheet1.searchDate).Row).Value = Application.UserName

MinutesElapsed = format((Timer - StartTime) / 86400, "hh:mm:ss")

MsgBox "Data Import Completed in " & MinutesElapsed

Else
'do nothing

End If

Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
'Application.DisplayAlerts = True

End Sub

最佳答案

如果您不想保存数据,请尝试使用 ActiveWorkbook.Close False .这将在不保存(无提示)且不使用 DisplayAlerts 行的情况下关闭工作簿。您还可以将事件工作簿设置为您需要的任何工作簿名称。

关于excel - "Application.DisplayAlerts = False"Excel崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36504278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com