FreezePanes without ActiveWindow

gauntletxg

Well-known Member
Joined
Jul 15, 2008
Messages
636
I'm automating some Excel tasks from another language (AutoIt), and have hit a snag with freezing panes. The basic structure of the AutoIt code is

Code:
$xlApp = ObjCreate("Excel.Application")
If Not IsObj($xlApp) Then Exit
With $xlApp
     .Visible = False
     ; A bunch of stuff
     .Quit
EndWith
Everything works fine, except the code I have in my Excel macro to freeze panes doesn't work, as the application is not visible and thus there's no active Excel window to work with. Is there a way I can freeze panes in this context? The only thing I can think of is ActiveSheet.FreezePanes, but that doesn't work.

Thanks.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
OK, there are some idiosyncrasies at work here, which can get confusing for this to work in your case, because the full context of your code is not evident.

FreezePanes is a property of a Window and of the ActiveWindow. Note, key words here (believe it or not) are "a" and "the".

The ActiveWindow is the window that is active, meaning it needs to be activated (selected) for it to be active, as there can only be one ActiveWindow in a single instance of Excel, hence the significance of the word "the".

A Window can be another workbook in the same instance of Excel, or a second Window in the same workbook such as if you click Window > New Window for the active workbook. In that respect, a Window does not need to be active for FreezePanes to be set. However, if for example you have Sheet1 active and you create a new window, and in that window you activate Sheet2, then re-activate your first (original) window to be on Sheet1 and you exectute
Windows(2).FreezePanes = True
it will freeze panes on Sheet2 in the second window but not Sheet2 on the window you are actively on.

So in your case, where this leaves you might be right smack in the middle, where you are creating an Excel object, which (and this is where I cannot tell) may or may not be in the same instance of Excel. If you are creating a seperate instance, that instance will not be recognized as a Window in the Windows collection of your active workbook.

If the Excel app yuou are creating is a part of your current active workbook's Window collection, you could execute this codeline to freeze panes on that unselected Window app...
Windows(2).FreezePanes = True
...assuming it is the second Window in your collection, as an example.

Otherwise, you are out of luck unless you make visible that xl object being created, make it active, and then set the Freeze Panes at that point.
 
Upvote 0

Forum statistics

Threads
1,224,087
Messages
6,176,280
Members
452,718
Latest member
Nyxs_Inquisitor

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top