PowerShell:無法取得工作簿類別的開放屬性

PowerShell:無法取得工作簿類別的開放屬性

所以我嘗試使用 PowerShell 開啟 Excel 檔案。但我收到此錯誤訊息:「無法取得工作簿類別的開放屬性」。

$dirPath = ("C:\Users\localadmin\OneDrive\DailyReports\")
$manFile = Get-ChildItem -Path $dirPath -Recurse -Filter "*MANSUM*"
$manPath = $manFile.Fullname
$excel = New-Object -ComObject Excel.Application
$excel.DisplayAlerts = $false
$manWB = $excel.Workbooks.Open($manPath)

我該如何修復這個錯誤?

完整路徑 ( $manPath) 是正確的。

運行 Windows 10 專業版、Excel 2016

答案1

這是一個解決方案:

需要建立資料夾並提供適當的存取權限。

・Windows 2008 伺服器 x64

請製作這個資料夾。

C:\Windows\SysWOW64\config\systemprofile\Desktop

・Windows 2008 伺服器 x86

請製作這個資料夾。

C:\Windows\System32\config\systemprofile\Desktop

參考: https://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-x64?論壇=創新辦公室

相關內容