Opening Ecel 2019 file error

Hello,

I’m working on a project to encrypt PDF files from a list in excel. I have been unable to open the .XLSX with the following error

PS C:\WINDOWS\system32> C:\PDF\Script1.ps1
GAC    Version        Location
---    -------        --------
False  v2.0.50727     c:\pdf\ITextSharp.dll
Confirm Variables--->
Excel-instance:Microsoft.Office.Interop.Excel.ApplicationClass
FilePath:C:\pdf\Book1.xlsx
<You cannot call a method on a null-valued expression.
At C:\PDF\Script1.ps1:39 char:1
+ $wb = $excel.Workbooks.Open($FilePath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

The property 'sheets' cannot be found on this object. Verify that the property exists.
At C:\PDF\Script1.ps1:42 char:12
+ for ($i=1; $i -le $wb.sheets.count; $i++)
+            ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
+ FullyQualifiedErrorId : PropertyNotFoundStrict

You cannot call a method on a null-valued expression.
At C:\PDF\Script1.ps1:70 char:1
+ $excel.Workbooks.Close()
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
________________________________
Original Script:
PS C:\WINDOWS\system32> C:\PDF\Script1.ps1
GAC    Version        Location
---    -------        --------
False  v2.0.50727     c:\pdf\ITextSharp.dll
Confirm Variables--->
Excel-instance:Microsoft.Office.Interop.Excel.ApplicationClass
FilePath:C:\pdf\Book1.xlsx
You cannot call a method on a null-valued expression.
At C:\PDF\Script1.ps1:39 char:1
+ $wb = $excel.Workbooks.Open($FilePath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

The property 'sheets' cannot be found on this object. Verify that the property exists.
At C:\PDF\Script1.ps1:42 char:12
+ for ($i=1; $i -le $wb.sheets.count; $i++)
+            ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
+ FullyQualifiedErrorId : PropertyNotFoundStrict

You cannot call a method on a null-valued expression.
At C:\PDF\Script1.ps1:70 char:1
+ $excel.Workbooks.Close()
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Any assistance will be appreciated.
Thanks

Posting your code or a similar one here will help us to understand the issue better.

using the .net methods for excel kind of sucks.

I generally use import-excel when i “have” to deal with excel.

https://www.powershellgallery.com/packages/ImportExcel/5.4.0

is there any actual requirement to use an excel document?
if you can open and save the sheet as a csv file your life gets alot easier