ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide a Workbook (https://www.excelbanter.com/excel-programming/373992-hide-workbook.html)

AnthonyJ

Hide a Workbook
 
With this code in a macro for Excel XP in VBA, I open an 'output' document
and then it in turn opens a source document so that the cells can update. I
want to hide the source document when it opens, but leave all other Excel
files, especially the one I just opened, unhidden. Sometimes this works and
sometimes it doesn't. Could anyone tell me why, or tell me if there is a
better code to make sure I am just hiding the source document?

The code in "This Workbook" object of the 'output':

' Code Purpose: When opening output (slave) document, open main to update
the cells correctly.
Private Sub Workbook_Open()

Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks("Workbook.xls")
If Not wb Is Nothing Then Exit Sub
On Error GoTo 0
' Freeze screen, no screen flickering during the running of the macro.
Application.ScreenUpdating = False
'Opening the main document:
Workbooks.Open "Workbook.xls"
'Hiding the main document:
ActiveWindow.Visible = False
Application.ScreenUpdating = True
End Sub

Thanks a lot!
--
AnthonyJ

Jim Rech

Hide a Workbook
 
Sometimes this works and sometimes it doesn't.

You really need to be more specific here. What _exactly_ happens when it
doesn't work?

Have you tried adding a Stop just before the ActiveWindow.Visible = False to
see what happens?


--
Jim
"AnthonyJ" wrote in message
...
| With this code in a macro for Excel XP in VBA, I open an 'output' document
| and then it in turn opens a source document so that the cells can update.
I
| want to hide the source document when it opens, but leave all other Excel
| files, especially the one I just opened, unhidden. Sometimes this works
and
| sometimes it doesn't. Could anyone tell me why, or tell me if there is a
| better code to make sure I am just hiding the source document?
|
| The code in "This Workbook" object of the 'output':
|
| ' Code Purpose: When opening output (slave) document, open main to update
| the cells correctly.
| Private Sub Workbook_Open()
|
| Dim wb As Workbook
| On Error Resume Next
| Set wb = Workbooks("Workbook.xls")
| If Not wb Is Nothing Then Exit Sub
| On Error GoTo 0
| ' Freeze screen, no screen flickering during the running of the macro.
| Application.ScreenUpdating = False
| 'Opening the main document:
| Workbooks.Open "Workbook.xls"
| 'Hiding the main document:
| ActiveWindow.Visible = False
| Application.ScreenUpdating = True
| End Sub
|
| Thanks a lot!
| --
| AnthonyJ



AnthonyJ

Hide a Workbook
 
Sorry, you're right, I should have been more specific. What I meant is,
sometimes it works the way I want, meaning the output doucument that I opened
opens and is visible, while the source document is opens and is hidden, and
the cells update. That is perfect. However, sometimes both documents open,
the cells update, but then both of the documents are hidden. I don't want
that. I need whoever is using the system to be able to see the output
document. That is the only thing wrong, and like I said, I can't seem to
figure out a reason for why it works for some documents, but for others with
the exact same macros, it hides both. I was just wondering if there was a
way to specify that I want to hide only the main document, rather than just
hiding the active window.

When I added the stop, it worked properly, and has been working since... why
on earth would that be... Still, is there any reason why this would happen
sometimes?

Thanks for taking the time to look at this
--
AnthonyJ


"Jim Rech" wrote:

Sometimes this works and sometimes it doesn't.


You really need to be more specific here. What _exactly_ happens when it
doesn't work?

Have you tried adding a Stop just before the ActiveWindow.Visible = False to
see what happens?


--
Jim
"AnthonyJ" wrote in message
...
| With this code in a macro for Excel XP in VBA, I open an 'output' document
| and then it in turn opens a source document so that the cells can update.
I
| want to hide the source document when it opens, but leave all other Excel
| files, especially the one I just opened, unhidden. Sometimes this works
and
| sometimes it doesn't. Could anyone tell me why, or tell me if there is a
| better code to make sure I am just hiding the source document?
|
| The code in "This Workbook" object of the 'output':
|
| ' Code Purpose: When opening output (slave) document, open main to update
| the cells correctly.
| Private Sub Workbook_Open()
|
| Dim wb As Workbook
| On Error Resume Next
| Set wb = Workbooks("Workbook.xls")
| If Not wb Is Nothing Then Exit Sub
| On Error GoTo 0
| ' Freeze screen, no screen flickering during the running of the macro.
| Application.ScreenUpdating = False
| 'Opening the main document:
| Workbooks.Open "Workbook.xls"
| 'Hiding the main document:
| ActiveWindow.Visible = False
| Application.ScreenUpdating = True
| End Sub
|
| Thanks a lot!
| --
| AnthonyJ




Jim Rech

Hide a Workbook
 
If a workbook is saved when it is hidden it will open hidden. If a workbook
opens hidden it will not be the active window. So ActiveWindow.Visible =
False will operate on another window. Then you have two windows hidden. I
think when you have this problem your Workbook.xls was last saved hidden.

You should specify the window like this:

Workbooks("Workbook.xls").Windows(1).Visible = False

If the window is already hidden this does no harm.

--
Jim
"AnthonyJ" wrote in message
...
| Sorry, you're right, I should have been more specific. What I meant is,
| sometimes it works the way I want, meaning the output doucument that I
opened
| opens and is visible, while the source document is opens and is hidden,
and
| the cells update. That is perfect. However, sometimes both documents
open,
| the cells update, but then both of the documents are hidden. I don't want
| that. I need whoever is using the system to be able to see the output
| document. That is the only thing wrong, and like I said, I can't seem to
| figure out a reason for why it works for some documents, but for others
with
| the exact same macros, it hides both. I was just wondering if there was a
| way to specify that I want to hide only the main document, rather than
just
| hiding the active window.
|
| When I added the stop, it worked properly, and has been working since...
why
| on earth would that be... Still, is there any reason why this would happen
| sometimes?
|
| Thanks for taking the time to look at this
| --
| AnthonyJ
|
|
| "Jim Rech" wrote:
|
| Sometimes this works and sometimes it doesn't.
|
| You really need to be more specific here. What _exactly_ happens when
it
| doesn't work?
|
| Have you tried adding a Stop just before the ActiveWindow.Visible =
False to
| see what happens?
|
|
| --
| Jim
| "AnthonyJ" wrote in message
| ...
| | With this code in a macro for Excel XP in VBA, I open an 'output'
document
| | and then it in turn opens a source document so that the cells can
update.
| I
| | want to hide the source document when it opens, but leave all other
Excel
| | files, especially the one I just opened, unhidden. Sometimes this
works
| and
| | sometimes it doesn't. Could anyone tell me why, or tell me if there
is a
| | better code to make sure I am just hiding the source document?
| |
| | The code in "This Workbook" object of the 'output':
| |
| | ' Code Purpose: When opening output (slave) document, open main to
update
| | the cells correctly.
| | Private Sub Workbook_Open()
| |
| | Dim wb As Workbook
| | On Error Resume Next
| | Set wb = Workbooks("Workbook.xls")
| | If Not wb Is Nothing Then Exit Sub
| | On Error GoTo 0
| | ' Freeze screen, no screen flickering during the running of the macro.
| | Application.ScreenUpdating = False
| | 'Opening the main document:
| | Workbooks.Open "Workbook.xls"
| | 'Hiding the main document:
| | ActiveWindow.Visible = False
| | Application.ScreenUpdating = True
| | End Sub
| |
| | Thanks a lot!
| | --
| | AnthonyJ
|
|
|



AnthonyJ

Hide a Workbook
 
Thanks for the help, Jim. It is much appreciated
--
AnthonyJ


"Jim Rech" wrote:

If a workbook is saved when it is hidden it will open hidden. If a workbook
opens hidden it will not be the active window. So ActiveWindow.Visible =
False will operate on another window. Then you have two windows hidden. I
think when you have this problem your Workbook.xls was last saved hidden.

You should specify the window like this:

Workbooks("Workbook.xls").Windows(1).Visible = False

If the window is already hidden this does no harm.

--
Jim
"AnthonyJ" wrote in message
...
| Sorry, you're right, I should have been more specific. What I meant is,
| sometimes it works the way I want, meaning the output doucument that I
opened
| opens and is visible, while the source document is opens and is hidden,
and
| the cells update. That is perfect. However, sometimes both documents
open,
| the cells update, but then both of the documents are hidden. I don't want
| that. I need whoever is using the system to be able to see the output
| document. That is the only thing wrong, and like I said, I can't seem to
| figure out a reason for why it works for some documents, but for others
with
| the exact same macros, it hides both. I was just wondering if there was a
| way to specify that I want to hide only the main document, rather than
just
| hiding the active window.
|
| When I added the stop, it worked properly, and has been working since...
why
| on earth would that be... Still, is there any reason why this would happen
| sometimes?
|
| Thanks for taking the time to look at this
| --
| AnthonyJ
|
|
| "Jim Rech" wrote:
|
| Sometimes this works and sometimes it doesn't.
|
| You really need to be more specific here. What _exactly_ happens when
it
| doesn't work?
|
| Have you tried adding a Stop just before the ActiveWindow.Visible =
False to
| see what happens?
|
|
| --
| Jim
| "AnthonyJ" wrote in message
| ...
| | With this code in a macro for Excel XP in VBA, I open an 'output'
document
| | and then it in turn opens a source document so that the cells can
update.
| I
| | want to hide the source document when it opens, but leave all other
Excel
| | files, especially the one I just opened, unhidden. Sometimes this
works
| and
| | sometimes it doesn't. Could anyone tell me why, or tell me if there
is a
| | better code to make sure I am just hiding the source document?
| |
| | The code in "This Workbook" object of the 'output':
| |
| | ' Code Purpose: When opening output (slave) document, open main to
update
| | the cells correctly.
| | Private Sub Workbook_Open()
| |
| | Dim wb As Workbook
| | On Error Resume Next
| | Set wb = Workbooks("Workbook.xls")
| | If Not wb Is Nothing Then Exit Sub
| | On Error GoTo 0
| | ' Freeze screen, no screen flickering during the running of the macro.
| | Application.ScreenUpdating = False
| | 'Opening the main document:
| | Workbooks.Open "Workbook.xls"
| | 'Hiding the main document:
| | ActiveWindow.Visible = False
| | Application.ScreenUpdating = True
| | End Sub
| |
| | Thanks a lot!
| | --
| | AnthonyJ
|
|
|





All times are GMT +1. The time now is 10:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com