I\'m working on a VBA project based in a workbook. The code opens a new workbook and calls an external API which downloads and inserts a bunch of data in multiple worksheets
You either need to save and close the target workbook, or select the original workbook before screenupdating is turned back on.
You could try using the ShowWindow API function:
Public Declare Function ShowWindow Lib "user32.dll" _
(ByVal HWND As Long, ByVal nCmdShow As Long) As Long
Const SW_HIDE as Long = 0
Const SW_SHOW as Long = 5
ShowWindow otherWorkbookApplication.Hwnd, SW_HIDE
'Your code here
ShowWindow otherWorkbookApplication.Hwnd, SW_SHOW
Or alternatively, the LockWindowUpdate API function (thanks to Chip Pearson, http://www.cpearson.com/excel/vbe.aspx):
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal ClassName As String, ByVal WindowName As String) As Long
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hWndLock As Long) As Long
Sub EliminateScreenFlicker()
Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If
'''''''''''''''''''''''''
' your code here
'''''''''''''''''''''''''
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub
Hiding the active workbook is possible with
ActiveWorkbook.Windows(1).Visible = False
You may need to replace ActiveWorkbook
with an appropriate reference if the workbook in question is not the active one and/or add a loop like For i = 1 To ActiveWorkbook.Windows.Count
if the workbook has multiple windows.