gpt4 book ai didi

vba - VBA代码中途重启,没有错误消息

转载 作者:行者123 更新时间:2023-12-03 08:54:27 25 4
gpt4 key购买 nike

我有以下代码,但似乎工作正常,但是在调试一半时,它会停止并重新启动。

重新启动时不会显示任何错误消息。有谁知道我的代码为什么这样做?

谢谢
SB

Sub ExportPICs()

If FileIsOpen("U:\FBS\PROJECTS_TEAM\MI\Sean's Projects\PICS and Benefits\Pics & Benefits upload file.xlsm") Then
MsgBox "That file's open, or doesn't exist - do something else."
Exit Sub
End If

Sheets("Post Implementation Costs").Visible = True
Sheets("Post Implementation Costs").Activate
Sheets("Post Implementation Costs").Unprotect Password:="Projects123"

Dim Tracker As String
Tracker = ThisWorkbook.Name

Dim wkbk As Excel.Workbook
Set wkbk = Workbooks.Open(Filename:= _
"U:\FBS\PROJECTS_TEAM\MI\Sean's Projects\PICS and Benefits\Pics & Benefits upload file.xlsm") '***********CODE RESTARTS HERE WITHOUT ERROR MESSAGE

Dim pics As String
pics = Dir("U:\FBS\PROJECTS_TEAM\MI\Sean's Projects\PICS and Benefits\Pics & Benefits upload file.xlsm")


Workbooks(Tracker).Activate
Sheets("Post Implementation Costs").Activate

Dim rng As Range
Dim CountTrue As Long
Set rng = Range("D16:D100")
CountTrue = Application.WorksheetFunction.CountIf(rng, "PIC")

If CountTrue > 0 Then
Rows("19:" & (CountTrue + 18)).EntireRow.Copy
End If

End Sub

最佳答案

如果“Pics&Benefits upload file.xlsm”中的“工作簿打开事件”中有任何代码可以执行循环。

试试Application.EnableEvents = False
之前

Dim wkbk As Excel.Workbook
Set wkbk = Workbooks.Open(Filename:= _
"U:\FBS\PROJECTS_TEAM\MI\Sean's Projects\PICS and Benefits\Pics & Benefits upload file.xlsm")

之后,您可以再次激活它。
Application.EnableEvents = True
此代码阻止Excel事件处理程序被调用。通常将其设置为false是因为事件处理程序的效果不理想,或者是为了防止无限循环。

关于vba - VBA代码中途重启,没有错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31516461/

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