Hi, is it possible to write code that hides the open word document
from view (but doesn't actually close it) and vice versa.

I know you can hide workbooks in excel, but i cant see that you can do
the same in Word so cant even begin to try and code it.

Cheers.

RE: Hiding open document by JeanGuyMarcil

JeanGuyMarcil
Thu May 08 12:20:02 PDT 2008

"macroapa" wrote:

> Hi, is it possible to write code that hides the open word document
> from view (but doesn't actually close it) and vice versa.
>
> I know you can hide workbooks in excel, but i cant see that you can do
> the same in Word so cant even begin to try and code it.
>

Here is some code to get you going...

Sub HideDoc()

ActiveDocument.ActiveWindow.Visible = False

End Sub

Sub resetHiddenDoc()

Dim myDoc As Document

For Each myDoc In Application.Documents
If myDoc.ActiveWindow.Visible = False Then myDoc.ActiveWindow.Visible =
True
Next

End Sub


Re: Hiding open document by macroapa

macroapa
Thu May 08 13:06:25 PDT 2008

On 8 May, 20:20, Jean-Guy Marcil
<JeanGuyMar...@discussions.microsoft.com> wrote:
> "macroapa" wrote:
> > Hi, is it possible to write code that hides the open word document
> > from view (but doesn't actually close it) and vice versa.
>
> > I know you can hide workbooks in excel, but i cant see that you can do
> > the same in Word so cant even begin to try and code it.
>
> Here is some code to get you going...
>
> Sub HideDoc()
>
> ActiveDocument.ActiveWindow.Visible =3D False
>
> End Sub
>
> Sub resetHiddenDoc()
>
> Dim myDoc As Document
>
> For Each myDoc In Application.Documents
> =A0 =A0 If myDoc.ActiveWindow.Visible =3D False Then myDoc.ActiveWindow.Vi=
sible =3D
> True
> Next
>
> End Sub

thanks for that, it's not quite doing what i want thou. The code i
will be using based on what you have said is:

Documents("xyz.dot").activewindow.visible =3D false
Documents.open ("abc.doc")

however, this leaves abc.doc also hidden. What I need is xyz,dot to be
hidden and abc.doc remain viewable, this is so i can easily debug the
code that actually sits in xyz.dot without it getting in the way of
what the code is doing (if i leave xyz.dot open, then my code can end
up putting text in xyz.dot instead of abc.doc)

cheers.



Re: Hiding open document by gordon(dot)bentleymix(at)gmail(dot)com>

gordon(dot)bentleymix(at)gmail(dot)com>
Thu May 08 18:31:00 PDT 2008

If I understand your post correctly, the problem is probably best solved not
by trying to hide a document but rather by restructuring your code so you
make specific reference to a particular document. These sorts of problems
come up when using the ActiveDocument object and stepping code to debug it.
Word recognises the ActiveDocument as the one that has focus. However, if you
create a new Document object and set that object to refer to a specific
document ("abc.doc" in your example) then write your code against the object,
the problem goes away.

The basic structure of the code is something along the lines of the following:

Sub Test()
Dim myDoc As Document
Dim Message As String
Set myDoc = Documents.Open("doc17.doc")
'*** Do stuff with myDoc; e.g. display a count of the tables in the
document ***
With myDoc
Select Case .Tables.Count
Case 0
Message = "There are no tables in this document."
Case 1
Message = "There is 1 table in this document."
Case Else
Message = "There are " & myDoc.Tables.Count & " tables in this
document."
End Select
MsgBox Message
myDoc.Close wdDoNotSaveChanges
End With
Set myDoc = Nothing
End Sub

Obviously this is a greatly simplified example (and not very useful because
I can't imagine why anybody would want to open a document, display a count of
the tables in it and then just close it again - but it worked for a
proof-of-concept using what I had easily available on my machine). However,
it should give you an idea of how to restructure your code to ensure that you
don't bugger up your template when you're developing.

Plus this makes a lot more sense than writing some 'throw-away' code for
debugging purposes only; any code you write against the specific document
object will work equally well in production. And it's just good practice to
refer to specific instances of objects rather than relying on something as
generic as the ActiveDocument or a UserForm class (yes Jean-Guy? ;-D).
--
Cheers!
Gordon
The Kiwi Koder

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


"macroapa" wrote:

> On 8 May, 20:20, Jean-Guy Marcil
> <JeanGuyMar...@discussions.microsoft.com> wrote:
> > "macroapa" wrote:
> > > Hi, is it possible to write code that hides the open word document
> > > from view (but doesn't actually close it) and vice versa.
> >
> > > I know you can hide workbooks in excel, but i cant see that you can do
> > > the same in Word so cant even begin to try and code it.
> >
> > Here is some code to get you going...
> >
> > Sub HideDoc()
> >
> > ActiveDocument.ActiveWindow.Visible = False
> >
> > End Sub
> >
> > Sub resetHiddenDoc()
> >
> > Dim myDoc As Document
> >
> > For Each myDoc In Application.Documents
> > If myDoc.ActiveWindow.Visible = False Then myDoc.ActiveWindow.Visible =
> > True
> > Next
> >
> > End Sub
>
> thanks for that, it's not quite doing what i want thou. The code i
> will be using based on what you have said is:
>
> Documents("xyz.dot").activewindow.visible = false
> Documents.open ("abc.doc")
>
> however, this leaves abc.doc also hidden. What I need is xyz,dot to be
> hidden and abc.doc remain viewable, this is so i can easily debug the
> code that actually sits in xyz.dot without it getting in the way of
> what the code is doing (if i leave xyz.dot open, then my code can end
> up putting text in xyz.dot instead of abc.doc)
>
> cheers.
>
>
>

Re: Hiding open document by gordon(dot)bentleymix(at)gmail(dot)com>

gordon(dot)bentleymix(at)gmail(dot)com>
Thu May 08 19:14:01 PDT 2008

Apologies for the extraneous 'myDoc' in the line:

myDoc.Close wdDoNotSaveChanges

In my haste to put together my POC, I missed the fact that I was still
within the bounds of the With block. The line should be:

.Close wdDoNotSaveChanges
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.


"Gordon Bentley-Mix" wrote:

> If I understand your post correctly, the problem is probably best solved not
> by trying to hide a document but rather by restructuring your code so you
> make specific reference to a particular document. These sorts of problems
> come up when using the ActiveDocument object and stepping code to debug it.
> Word recognises the ActiveDocument as the one that has focus. However, if you
> create a new Document object and set that object to refer to a specific
> document ("abc.doc" in your example) then write your code against the object,
> the problem goes away.
>
> The basic structure of the code is something along the lines of the following:
>
> Sub Test()
> Dim myDoc As Document
> Dim Message As String
> Set myDoc = Documents.Open("doc17.doc")
> '*** Do stuff with myDoc; e.g. display a count of the tables in the
> document ***
> With myDoc
> Select Case .Tables.Count
> Case 0
> Message = "There are no tables in this document."
> Case 1
> Message = "There is 1 table in this document."
> Case Else
> Message = "There are " & myDoc.Tables.Count & " tables in this
> document."
> End Select
> MsgBox Message
> myDoc.Close wdDoNotSaveChanges
> End With
> Set myDoc = Nothing
> End Sub
>
> Obviously this is a greatly simplified example (and not very useful because
> I can't imagine why anybody would want to open a document, display a count of
> the tables in it and then just close it again - but it worked for a
> proof-of-concept using what I had easily available on my machine). However,
> it should give you an idea of how to restructure your code to ensure that you
> don't bugger up your template when you're developing.
>
> Plus this makes a lot more sense than writing some 'throw-away' code for
> debugging purposes only; any code you write against the specific document
> object will work equally well in production. And it's just good practice to
> refer to specific instances of objects rather than relying on something as
> generic as the ActiveDocument or a UserForm class (yes Jean-Guy? ;-D).
> --
> Cheers!
> Gordon
> The Kiwi Koder
>
> Uninvited email contact will be marked as SPAM and ignored. Please post all
> follow-ups to the newsgroup.
>
>
> "macroapa" wrote:
>
> > On 8 May, 20:20, Jean-Guy Marcil
> > <JeanGuyMar...@discussions.microsoft.com> wrote:
> > > "macroapa" wrote:
> > > > Hi, is it possible to write code that hides the open word document
> > > > from view (but doesn't actually close it) and vice versa.
> > >
> > > > I know you can hide workbooks in excel, but i cant see that you can do
> > > > the same in Word so cant even begin to try and code it.
> > >
> > > Here is some code to get you going...
> > >
> > > Sub HideDoc()
> > >
> > > ActiveDocument.ActiveWindow.Visible = False
> > >
> > > End Sub
> > >
> > > Sub resetHiddenDoc()
> > >
> > > Dim myDoc As Document
> > >
> > > For Each myDoc In Application.Documents
> > > If myDoc.ActiveWindow.Visible = False Then myDoc.ActiveWindow.Visible =
> > > True
> > > Next
> > >
> > > End Sub
> >
> > thanks for that, it's not quite doing what i want thou. The code i
> > will be using based on what you have said is:
> >
> > Documents("xyz.dot").activewindow.visible = false
> > Documents.open ("abc.doc")
> >
> > however, this leaves abc.doc also hidden. What I need is xyz,dot to be
> > hidden and abc.doc remain viewable, this is so i can easily debug the
> > code that actually sits in xyz.dot without it getting in the way of
> > what the code is doing (if i leave xyz.dot open, then my code can end
> > up putting text in xyz.dot instead of abc.doc)
> >
> > cheers.
> >
> >
> >

Re: Hiding open document by JeanGuyMarcil

JeanGuyMarcil
Fri May 09 05:10:00 PDT 2008

"macroapa" wrote:

> thanks for that, it's not quite doing what i want thou. The code i
> will be using based on what you have said is:
>
> Documents("xyz.dot").activewindow.visible = false
> Documents.open ("abc.doc")
>
> however, this leaves abc.doc also hidden. What I need is xyz,dot to be
> hidden and abc.doc remain viewable, this is so i can easily debug the

Open abc.doc before hiding xyz.dot...

> code that actually sits in xyz.dot without it getting in the way of
> what the code is doing (if i leave xyz.dot open, then my code can end
> up putting text in xyz.dot instead of abc.doc)

...however, I will second Gordon on this.
If you worry that code in a project might act on the wrong document, then
you need to review your code.
Anyway, the code might still act on the wrong document if it is merely
hidden...
Use Document objects to get a handle on the appropriate document and avoid
using the Selection opbject.