ActiveWindow option in code stage

kulranjan

New Member
I want to create a page in the ms excel vbo to create freeze panes i have recorded a macro and the code for it is

With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True


The major issue is use of ActiveWindow as it can't be use like ActiveWorkbook or ActiveWorksheet, Is there any way we can ActivateWindow
 

Ritansh_Jatwani

New Member
I want to create a page in the ms excel vbo to create freeze panes i have recorded a macro and the code for it is

With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True


The major issue is use of ActiveWindow as it can't be use like ActiveWorkbook or ActiveWorksheet, Is there any way we can ActivateWindow
ActiveWindow can also be used like ActiveWorkbook or ActiveWorksheet, its just we should be aware about the parent of the ActiveWindow.

The parent of ActiveWindow is Excel Application which can be easily identified using the workbook name. I have written the vb.net code to freeze the panes in Excel. In the below code, handle, workbook_name and range will be the input parameters and paste the below code in the code stage of the MS Excel VBO

VB.Net Code to freeze panes

Dim wb as Object

wb=GetWorkbook(handle,workbook_name).ActiveSheet
wb.Range(range).Select
wb.Application.ActiveWindow.FreezePanes = True
 

gil.silva

Active Member
Hello sunortap,

I believe you're using GetWorkbook and GetWorsheet to interact with the excel, right?

Therefore, you can use the following:

Code:
Dim wb, ws As Object
Dim excel As Object

wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)

wb.Activate()
ws.Activate()
excel = ws.Application

With excel.ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
End With

excel.ActiveWindow.FreezePanes = True

Let me know if it works for you.
 

kulranjan

New Member
Hello sunortap,

I believe you're using GetWorkbook and GetWorsheet to interact with the excel, right?

Therefore, you can use the following:

Code:
Dim wb, ws As Object
Dim excel As Object

wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)

wb.Activate()
ws.Activate()
excel = ws.Application

With excel.ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
End With

excel.ActiveWindow.FreezePanes = True

Let me know if it works for you.

Doesn't works
 

gil.silva

Active Member
Hello,

I'm sorry, I thought it was clear.
Worksheet, Workbook and Handle are your Inputs.

Handle - output from the 'Create Instance' action
Worksheet - name of the worksheet
Workbook - output from the Open Workbook action

Let me know if you need more assistance
 

ADITYA_RPA

New Member
Hello sunortap,

I believe you're using GetWorkbook and GetWorsheet to interact with the excel, right?

Therefore, you can use the following:

Code:
Dim wb, ws As Object
Dim excel As Object

wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)

wb.Activate()
ws.Activate()
excel = ws.Application

With excel.ActiveWindow
    .SplitColumn = 0
    .SplitRow = 1
End With

excel.ActiveWindow.FreezePanes = True

Let me know if it works for you.
Hi @gil.silva
can you help me to create the unfreeze worksheeet action
 
Top