VBA-Worksheet.activate不起作用

问题描述 投票:0回答:1

我想知道您是否可以帮助我弄清楚为什么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
excel vba worksheet
1个回答
0
投票

我也遇到了“ WorkSheet_Activate(和_Deactivate)不起作用的问题”。我至少已针对我的情况找到了解决方案。工作表更改(通过编程方式或手动方式)激活了包含某些条件格式的工作表,这些条件格式具有UDF(非常简单的VBA功能)。删除了这些特定条件后,后来又用Excel公式替换,该问题完全消失了。

© www.soinside.com 2019 - 2024. All rights reserved.