ActiveWindow not switching properly in Excel

K

kdw

I had posted a similar question in the Excel forum but didn't get a solution
so I'll try here. I hope someone can help.

I reference the Excel objects to export data to. then I freeze the pane using

objXLSheet.Activate
objXLSheet.Range("E3").Select
ActiveWindow.FreezePanes = True

Set objXLSheet = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing

This works fine the first time, but subsequent runs still reference the
first workbook as the Activewindow. What is wrong?

Is there a way to release or change the reference to the Activewindow?

Thanks!
 
G

Grochu

There is e little bit too less code to answer your question.

Actually, I suppose, there is something wrong with activating a proper
workbook - it looks like you would not activate any workbook, but
worksheet only:
If objXLSheet is declared as Excel Sheet where is the following line:
Window(index).Activate
 
K

kdw

This does gave me a lead to check into the window object. I am able to make
this work now by quantifying ActiveWindow as follow:

objXLApp.ActiveWindow.FreezePanes = False
objXLSheet.Range("D3").Select
objXLApp.ActiveWindow.FreezePanes = True

I guess since objXLApp creates a new Excel object each time I run the
procedure, ActiveWindow can still be pointing to the previous object if I am
not specific enough?
Is there a way to kill the reference to the prior object? I used "Set
objXLApp= Nothing" but that doesn't help. Just want to know the details
behind the scene.

Anyway, this does work now. thanks Grochu!
 

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