Invisible document

H

Helmut Weber

Hi Tony,

Sub Makro1()
Dim oDcm As Document
Set oDcm = Documents.Add(Visible:=False)
oDcm.Range.Text = "xxxxxxxxxxxxxx"
MsgBox oDcm.Windows.Count ' = 0
' understandable as there is no window yet
' oDcm.Windows(1).Visible = True 'results in error 5941
oDcm.Windows.Add
oDcm.Windows(1).Visible = True ' ok so far
' but now oDcm has 2 (!) windows
MsgBox oDcm.Windows.Count ' = 2 ???
End Sub

What's wrong?
 
T

Tony Jollans

I don't know what's wrong. I did check before I posted (I can't remember
exactly what I did) but can''t make it work now.

However, one of the zero windows, it seems, is the active window, and this
appears to work - except that the window has no caption - and still isn't
included in the collection..

Sub Makro1()
Dim oDcm As Document
Set oDcm = Documents.Add(Visible:=False)
oDcm.Range.Text = "xxxxxxxxxxxxxx"
MsgBox oDcm.Windows.Count ' = 0
' understandable as there is no window yet
' oDcm.Windows(1).Visible = True 'results in error 5941
oDcm.ActiveWindow.Visible = True ' seems to work
'oDcm.Windows.Add
'oDcm.Windows(1).Visible = True ' ok so far
' but now oDcm has 2 (!) windows
MsgBox oDcm.Windows.Count ' still 0 ????
End Sub
 
H

Helmut Weber

Hi Tony,

there is a mistake in the comments in my code.
After adding a window, to an unvisible document,
which has a windows.count of zero,
the document has a windows count of 2.

Dim oDcm As Document
Set oDcm = Documents.Add(Visible:=False)
oDcm.Range.Text = "xxxxxxxxxxxxxx"
MsgBox oDcm.Windows.Count ' = 0
oDcm.Windows.Add
MsgBox oDcm.Windows.Count ' = 2

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
T

Tony Jollans

Hi Helmut,

I thought your comment was correct to start with - are you just looking at
my changes to it?

Sub Makro1()

Dim oDcm As Document
Set oDcm = Documents.Add(Visible:=False)
oDcm.Range.Text = "xxxxxxxxxxxxxx"

MsgBox oDcm.Windows.Count ' = 0
oDcm.ActiveWindow.Visible = True ' seems to work
MsgBox oDcm.Windows.Count ' still 0 ????

End Sub

This just has to be a bug. I'm not sure whether an invisible document ought
to have an invisible window or not but I am sure any window it does have
should be in the windows collection.

This version seems to work round the problem ..

Sub Makro1()

Dim oDcm As Document
Set oDcm = Documents.Add(Visible:=False)
oDcm.Range.Text = "xxxxxxxxxxxxxx"

MsgBox oDcm.Windows.Count ' = 0
oDcm.Windows.Add.Close
MsgBox oDcm.Windows.Count ' now it's 'correct'

oDcm.Windows(1).Visible = True ' now it works

End Sub
 
H

Helmut Weber

Hi Tony,
This just has to be a bug.

Right.

That's want I wanted to have confirmened.

Your workaround is working.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top