I am trying to Unlock a Specific Column Range in Excel (Column I & J) by using an Invoke Code and I am also running other functions in this same block, like Hiding a specific Column etc.
I am able to Unlock all the Columns using "excelWS.Columns.Locked = False But whenever I try to specify a specific range I am just met with the following Exception
Invoke Code - Format Excel Worksheet: Exception has been thrown by the target of an invocation
This is how my Invoke Code is Setup:
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 'Unlock Columns' 'excelWS.Columns.Locked = False' excelWS.Range("I:J").EntireColumn.Locked = False excelWB.Save excelWB.Close excelApp.Quit
The problem line is the below:
excelWS.Range("I:J").EntireColumn.Locked = False