にWordのdocxファイルを変換する私はPDFへのWord DOCXのバッチ変換を行うためにPowerShellを使用しようとしています - このサイトに掲載されていたスクリプト使用: http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/24/weekend-scripter-convert-word-documents-to-pdf-files-with-powershell.aspx基本PowerShellの - バッチは、PDF
# Acquire a list of DOCX files in a folder
$Files=GET-CHILDITEM "C:\docx2pdf\*.DOCX"
$Word=NEW-OBJECT –COMOBJECT WORD.APPLICATION
Foreach ($File in $Files) {
# open a Word document, filename from the directory
$Doc=$Word.Documents.Open($File.fullname)
# Swap out DOCX with PDF in the Filename
$Name=($Doc.Fullname).replace("docx","pdf")
# Save this File as a PDF in Word 2010/2013
$Doc.saveas([ref] $Name, [ref] 17)
$Doc.close()
}
をそして、私は続けますこのエラーが発生し、理由を把握できません:
PS C:\docx2pdf> .\docx2pdf.ps1
Exception calling "SaveAs" with "16" argument(s): "Command failed"
At C:\docx2pdf\docx2pdf.ps1:13 char:13
+ $Doc.saveas <<<< ([ref] $Name, [ref] 17)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
アイデアをお持ちですか?
また、ローカルファイル(スクリプトの場所と同じ場所にあるファイル)を使用するだけでなく、doc(docXではなく)ファイルを変換するにはどのように変更する必要がありますか?
申し訳ありません - PowerShellスクリプトをやったことがない...
これは働いていた - 感謝 - '$のdocuments_path =分割経路-parent $ MyInvocation.MyCommand.Path' – takabanana
を使用してスクリプトの場所に基づいて動的にする$のdocuments_pathを変更OLEDBが使用されていますこの変換では? – culter
また、COMオブジェクトを解放する必要があります: '[System.Runtime.Interopservices.Marshal] :: ReleaseComObject($ word_app)'。変数全体を削除することも[The Scripting Guys](http://technet.microsoft.com/en-us/library/ff730962.aspx)で提案されています: 'Remove-Variable word_app' – ComFreek