39221

Code to hide only one workbook instead of hiding all currently open workbooks

I usually have multiple workbooks open and on one workbook, I have a VBA code that hides the workbook and shows a UserForm. But when I open that workbook, all of my workbooks that are currently opened will also hide. What code can I use to just hide 1 workbook?

Here are the codes I've tried:

ThisWorkbook.Application.Visible = False Windows(ThisWorkbook.name).Visible = False Application.Windows(1).visible = false

With Windows(ThisWorkBook.name).visible = False works with closing only one workbook, it messes with the workbook and the sheets don't show at all. I can't even close the excel workbook without using the task manager.

Answer1:

ThisWorkbook.Application.Visible = False will change the Visible property of the <strong>application</strong> running your workbook, i.e. an instance of Excel.EXE ... if this instance is running your other books, too, then as a consequence all these books will disappear from screen.

To hide a single workbook, use

ActiveWindow.Visible = False

or alternatively, if the workbook you want to hide (e.g. "MyWorkbook") is not the active one

Windows("MyWorkbook").Visible = False

Pay attention that hiding a window also moves the pointer to the ActiveSheet, likewise when you reverse this (i.e. ...Visible = True) the displayed sheet becomes active.

Recommend

  • Extract string between characters from a txt file in python [closed]
  • VBA: Runtime Error - SetSourceData for Second Pivot Chart
  • I need to create a stopping condition for my program
  • Show current time (EST)
  • ADO functionality.. copy, filter, paste from closed workbook to active wrokbook
  • Action when linked cell of option button changes
  • macro that auto-executes when sheet is opened
  • Excel 2007 VBA Zooming (without using select?)
  • Why does not field with custom function to get name recalculate?
  • Excel VBA code to move worksheets with image add screen updating and it errors
  • How to know if a JFrame is on screen in a multi screen environment
  • Accessing another variable in the same class with a click event
  • Why can't UI components be accessed from a backgroundworker?
  • How to getText() from the input field of an angularjs Application
  • Group list of tuples by item
  • Invalid object name 'dbo.Item'
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Query to find the duplicates between the name and number in table
  • Excel's Macro-Recorder usage
  • What and where is mdimport
  • zope_i18n_compile_mo_files doesn't work on a Zeo configuration
  • CakePHP 2.0.4 - findBy magic methods with conditions
  • How do I get HTML corresponding to current DOM tree?
  • PHP buffered output depending on server setting?
  • Why does access(2) check for real and not effective UID?
  • Is it possible to access block's scope in method?
  • Meteor helpers not available in Angular template
  • How to recover from a Spring Social ExpiredAuthorizationException
  • ILMerge & Keep Assembly Name
  • Javascript convert timezone issue
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Large data - storage and query
  • WOWZA + RTMP + HTML5 Playback?
  • How do you join a server to an Active Directory (domain)?
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs