Empêcher le scintillement de l'écran lors de l'ouverture d'un deuxième classur (même instance)

Préfixe : mon code ouvre un classur externe doté d'un DB interne avec des informations qui ne devraient pas être visibles pour l'set de l'organisation. Je peux ouvrir le classur externe et récupérer toutes datatables du PivotTable avec succès.

Problème : lorsque mon code fonctionne, l'écran clignote pendant ~ 0,5 seconde pour afficher l'autre classur.

But : ne pas avoir de scintillement sur l'écran lors de la transition entre les classurs.

Mon code (section pertinente):

 Option Explicit Public Sub GetBudgetData_fromPivotTable(Budget_ShtName As Ssortingng, Budget_PvtName As Ssortingng) Dim BudgetWB As Workbook Dim PvtTbl As PivotTable Dim pvtFld As PivotField Dim strPvtFld As Ssortingng Dim prjName As Ssortingng ' ****** This is the Section I am trying to prevent from the screen to flicker ****** Application.ScreenUpdating = False Application.DisplayAlerts = False ' read budget file parameters Set BudgetWB = Workbooks.Open(BudgetFile_Folder & BudgetFile_wbName) BudgetWB.Windows(1).Visible = False OriginalWB.Activate ' <-- this is the original workbook that is calling the routine Set PvtTbl = BudgetWB.Worksheets(Budget_ShtName).PivotTables(Budget_PvtName) ' a lot of un-relevant code line BudgetWB.Close (False) ' close budget file OriginalWB.Activate ' restore settings Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub 

Pour minimiser le scintillement de l'écran, je pense que ce qui suit devrait fonctionner; il ajoute l'étape supplémentaire consistant à cacher ActiveWindow une fois que ScreenUpdating a été désactivé pour permettre l'ouverture et le cache du classur avant de réinitialiser les niveaux de visibilité. Lorsque je l'ai essayé, le ruban semble désactiver et activer, mais la feuille de calcul est restée sans scintillement. Je ne sais pas si cela vous suffit d'une amélioration …

 Public Sub GetBudgetData_fromPivotTable(Budget_ShtName As Ssortingng, Budget_PvtName As Ssortingng) Dim BudgetWB As Workbook Dim PvtTbl As PivotTable Dim pvtFld As PivotField Dim strPvtFld As Ssortingng Dim prjName As Ssortingng ' ****** This is the Section I am trying to prevent from the screen to flicker ****** Dim wbWindow As Window: Set wbWindow = ActiveWindow ' Freeze current screen Application.ScreenUpdating = False wbWindow.Visible = False ' read budget file parameters Set BudgetWB = Workbooks.Open(BudgetFile_Folder & BudgetFile_wbName) BudgetWB.Windows(1).Visible = False ' Reset current screen wbWindow.Visible = True Application.ScreenUpdating = True OriginalWB.Activate ' <-- this is the original workbook that is calling the routine Set PvtTbl = BudgetWB.Worksheets(Budget_ShtName).PivotTables(Budget_PvtName) ' a lot of un-relevant code line BudgetWB.Close (False) ' close budget file OriginalWB.Activate ' restore settings Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub 

Un autre travail, cela fonctionnerait, si vous l'aimez. L'idée est que vous copyz la feuille avec le tableau pivot dans votre classur et que vous travaillez à partir de là. Faites la feuille cachée et une fois que vous êtes prêt avec le travail – supprimez-le.

 Option Explicit Sub ImportSheet() Dim wbBk As Workbook Dim wsSht As Worksheet Dim sImportFile As Ssortingng Dim sFile As Ssortingng Dim sThisBk As Workbook Dim vfilename As Variant Application.ScreenUpdating = False Application.DisplayAlerts = False Set sThisBk = ActiveWorkbook sImportFile = Application.GetOpenFilename( _ FileFilter:="Microsoft Excel Workbooks, *.xls; *.xlsx", Title:="Open Workbook") vfilename = Split(sImportFile, "\") sFile = vfilename(UBound(vfilename)) Application.Workbooks.Open Filename:=sImportFile Set wbBk = Workbooks(sFile) If SheetExists("MyPivotData") Then Set wsSht = wbBk.Sheets("MyPivotData") wsSht.Copy ThisWorkbook.Sheets("MyPivotData").Visible = xlSheetVeryHidden End If 'do your work 'then delete the added sheet wbBk.Close SaveChanges:=False Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub Private Function SheetExists(sWSName As Ssortingng) As Boolean Dim ws As Worksheet On Error Resume Next Set ws = Worksheets(sWSName) If Not ws Is Nothing Then SheetExists = True End Function