Problem opening a Word Doc using the Run PowerShell workflow activity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2014 11:18 AM
I'm trying to open a Word document on the MID Server by passing some script using the Run PowerShell workflow activity and it's failing with the error "You cannot call a method on a null-valued expression." I was wondering if anyone else has experienced the same issue.
Here's a simplified version of my script:
$file = '<my Word file located on the MID Server>'
$word = New-Object —ComObject Word.Application
$word.visible = $false
if (Test-Path $file) {
Write-Host $file ' exists'
$doc = $word.Documents.Open($file)
} else {
Write-Host $file ' does not exist'
}
I've narrowed the issue to the "$doc = $word.Documents.Open($file)" line. It appears the document is never opened so the local variable, $doc, is null which eventually results in the "You cannot call a method on a null-valued expression." error after trying to reference that variable in subsequent processes.
If I run this same exact script on the MID Server itself using PowerShell, it works perfectly. It just doesn't work when passed through Orchestration.
Any help would be greatly appreciated.
Thanks,
Michael
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2014 06:03 AM
For anyone interested in this thread, the issue I encountered turned out to be a Microsoft issue. But not in the sense that the issue is a bug. Turns out that Microsoft does not support server-side automation using their desktop applications.
From the KB article that outlines these considerations:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
I'm still looking for a server-side solution to automate some Word processing, specifically, converting a Word document to PDF. I've got a few ideas I'm experimenting with and if/when I find a suitable solution, I'll share me findings here.
Thanks for reading,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2014 07:05 AM
You have to create Desktop directory for system profile account.
For full explanation check this article: The Ether: Error 5151 or 5097 when opening a Word document using Office Automation from a COM object