UiPath - VB 网络 - Excel - 解锁特定列

UiPath - VB Net - Excel - Unlock Specific Column

我正在尝试使用调用代码解锁特定的列范围(列 I 和 J),并且我还在同一块中 运行 其他功能,例如隐藏特定的列等。

我可以使用“excelWS.Columns.Locked = False 解锁所有列 但是每当我尝试指定一个特定范围时,我都会遇到以下异常

Invoke Code - Format Excel Worksheet: Exception has been thrown by the target of an invocation

我的调用代码是这样设置的:

Dim excelWB As Microsoft.Office.Interop.Excel.Workbook
excelApp = New Microsoft.Office.Interop.Excel.ApplicationClass
excelWB = excelApp.Workbooks.Open(excelFilePath)
excelWS = CType(excelWB.Worksheets(excelSheet), Microsoft.Office.Interop.Excel.Worksheet)
'Hide the Column'
excelWS.Range("M:M").EntireColumn.Hidden = True
'Set Bottom Margin to 1.1'
excelWS.PageSetup.BottomMargin = excelApp.InchesToPoints(0.433070866141732)
'Fit to One Page Width'
excelWS.PageSetup.Zoom = False
excelWS.PageSetup.FitToPagesWide = 1
'Print Tile Rows'
excelWS.PageSetup.PrintTitleRows = ":"
'Header Page 1'
excelWS.PageSetup.CenterFooter = "Page &P"
'Unlock Columns'
'excelWS.Columns.Locked = False'
excelWS.Range("I:J").EntireColumn.Locked = False
excelWB.Save
excelWB.Close
excelApp.Quit

问题行如下:

excelWS.Range("I:J").EntireColumn.Locked = False

有什么建议吗?

谢谢

更新一下;结果整个列中有几个合并的单元格,所以一旦这些单元格被删除,它就会再次开始工作。