如何激活主工作簿并将其置于所有打开的excel文件的最前面?

时间:2019-05-06 17:42:23

标签: excel vba

此代码打开了一组工作簿,并且可以正常工作。但是,在打开工作簿之后,我希望从中运行宏的主工作簿被激活并置于最前面。 这是我的代码,它不会激活并将excel主文件置于最前面。

    Sub SkipBlankCells2()
Dim cell As Range, rng As Range, FName As String
Set rng = Range("E12:E24")

'Disable Screen Updating - stop screen flickering
'   And Disable Events to avoid inturupted dialogs / popups
With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

Application.DefaultFilePath = ActiveWorkbook.Path

For Each cel In rng
    If Len(cel) >= 1 Then
            FName = cel.Value
        Workbooks.Open Filename:=FName
    End If
Next cel

'Enable Screen Updating and Events
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

    'Return to master workbook
ThisWorkbook.Activate

End Sub

0 个答案:

没有答案