gpt4 book ai didi

excel - VBA - Worksheet.activate 不工作

转载 作者:行者123 更新时间:2023-12-04 19:50:48 28 4
gpt4 key购买 nike

我想知道您能否帮我弄清楚为什么 worksheet.activate 在下面的情况下什么都不做。我关掉

.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False,

-> 创建一个新文件并向其中添加工作表,-> 重新打开它们,-> 当我尝试激活新文件时,它什么也不做,主文件保持事件状态。

有没有人有这样的解决方案?

Enum getWhat
getRow = 0
getCol = 1
End Enum

Sub main()
SetProgramAlerts 0
Set currentWorkbook= ActiveWorkbook
Set newWorbook = Workbooks.add
With newWorbook
Set WS_Project = .Worksheets("Sheet1")
WS_Project.name = wsProject
'....
End with
SetProgramAlerts 1
newWorbook.Activate 'this actually does nothing, even though application.screenupdating = true
end sub

Public Sub setProgramAlerts(turnThem As turnThem)
'TURN EVERITHING OFF AT THE BEGINING OF A MACRO
'REMEMBER TO TURN BACK ON
DoEvents
Select Case turnThem
Case 0 'All off
With Application
If .ScreenUpdating Or .EnableEvents Or .DisplayAlerts Then
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End If

If Workbooks.Count > 0 Then
If .Calculation <> xlCalculationManual Then .Calculation = xlCalculationManual
End If
'.statusBar = True
End With

Case 1 'All on in opposite order
With Application
'.statusBar = False
If Workbooks.Count > 0 Then
.Calculation = xlCalculationAutomatic
End If

If .DisplayAlerts = False Or .EnableEvents = False Or .ScreenUpdating = False Then
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End If
End With
End Select
DoEvents
End Sub

最佳答案

我遇到了同样的问题。在 Application.ScreenUpdating = True 之前设置 sheet.activate 一切正常。

关于excel - VBA - Worksheet.activate 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51285063/

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