Excel.ActiveWindow Is Excel.ActiveWindow Returns False

  • Thread starter Thread starter Neal Andrews
  • Start date Start date
N

Neal Andrews

Hi All,

If need to be able to compare Excel Window objects the same as you can in MS
Word (or any other app)

If you do

Excel.ActiveWindow Is Excel.ActiveWindow

in Vba it always returns false, which is clearly incorrect.

It appears that Excel is returning a different object for every returned
Window, thus not allowing Window objects to be compared as they should. Does
any only know how to get a fix on the 'true' Window Object so Windows can be
compared.

Regards
Neal
 
Hi Neal,

You can grab a reference to a window and hold it, but you can't grab the
same thing again -

Set w1 = ActiveWindow
Set w2 = ActiveWindow

Set a = w1
Set b = w2

MsgBox a Is w1, , b Is w2 ' true true
MsgBox w1 Is w2, , a Is b ' false false

similar with any other window, eg Activeworkbook.windows(1)

The ActiveWindow is always ActiveWorkbook.Windows(1), assuming an
activeworkbook exists, yet some of the respective properties are different.

I could cite other anomalies

The application level windows is really a collection of all the Workbook's
windows, which in turn are the third level down from the true sole
application window.

You could store and compare window captions, though in the case of 'new'
windows the last part of the text is transitory and captions can be changed.

However, depending on your needs I suspect you might be better off storing
the a reference to the activeworkbook for later comparison.

Regards,
Peter T
 

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

Back
Top