Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding active workbook programmatically in Excel

Tags:

excel

screen

vba

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 of this new workbook. I deactivated Screen Updating (Application.Screenupdating = False) so initially the screen stays focused on the original workbook while the API downloads data on the other workbook in the background. However, the screen switches to the new workbook once the API inserts data. How can I prevent this from happening? Thanks!

like image 430
lodhb Avatar asked Jul 06 '12 00:07

lodhb


1 Answers

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.

like image 136
Paul B. Avatar answered Oct 11 '22 08:10

Paul B.