Freeze pane Prob & Activewindow

K

kdw

I am trying to freeze the pane of a workbook from an Export function in
another program using:

ActiveWindow.FreezePanes = True

This work fine for the first export. Subsequent export would not work. It
would end up freezing the pane if the first workbook, or worse, if the first
workbook was close, an error.

I found that Activewindow still refers to the first workbook, even if I
Activate the sheet/new workbook.

Any ideas? Is there a way to reset the Activewindow property for sure?

Thanks,
kdw
 
K

kdw

This doesn't quite change my issue of the Activewindow property pointing to
the wrong workbook. Perhaps I didn't explain my situation clearly.

My ExportToExcel procedure is written in VB in a non-Office program. After
exporting the data to Excel, I want to freeze the pane before exiting with
something like:

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

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

This works on the first export. The second time I call this procedure no
pane is frozen on the second workbook. If I close the first workbook, the
procedure would fail when I run it again. When I check the Activewindow
property, I found that it still refers to the first workbook no matter what I
do.

Can anyone tell what is my error?
Does not my code above cause objXlSheet to be in the Activewindow?
 
T

Tom Ogilvy

Just a heads up. Something doesn't appear to be right Gordon. A workbook
doesn't have an activewindow property. You haven't put periods infront of
ActiveWindow so there is no reason for the With statement. The code
should run fine as written, but again, the With statement is superfluous as
written. I suspect there is a typo here or an omitted statement - just
thought I would bring it to your attention if such is the case.

--
Regards,
Tom Ogilvy

Gord Dibben said:
kdw

This might help.

Sub Freeze_Panes()
With ActiveWorkbook
ActiveWindow.SplitRow = 2
ActiveWindow.FreezePanes = True
End With
End Sub


Gord Dibben Excel MVP
 
G

Gord Dibben

Thanks Tom

I had the code kicking around without the With ActiveWorkbook and End With
lines.

I mistakenly thought that adding those lines would point the OP's code to the
ActiveWorkbook instead of the original workbook.

They are superfluous as you say and Sub certainly wouldn't work without the
periods if the workbook did have an activewindow property.

I'm going back to the Tools>Options section now<g>

Gord
 

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