先日、「名前を付けて保存」するときにファイル拡張子を変更する良い方法を見つけようと、このスクリプトを投稿しました。問題をなめてもらいましたが、今朝の時点で、スクリプトはエラーなしでは実行されません。これが私が得ているエラーメッセージです:
Processing : C:\users\xxx\Desktop\ht\Automatic_Post-Call_Survey.htm
Exception calling "SaveAs" with "16" argument(s): "This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders."
At C:\users\xxx\Desktop\hd.ps1:11 char:20
+     $opendoc.saveas <<<< ([ref]"$docpath\$doc.FullName.doc", [ref]$saveFormat);
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
「16」がエラーコードである場合、それはディレクトリを削除できないことを表しています...しかし、どこかにデフォルトのパラメータがない限り、私がそれを求めているようには見えません。私はかなり困惑しています.誰も私が試すことができる他のアイデアを持っていますか?
$docpath = "c:\users\xxx\desktop\do"
$htmPath = "c:\users\xxx\desktop\ht"
$srcfiles = Get-ChildItem $htmPath -filter "*.htm*"
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument"); 
$word = new-object -comobject word.application 
$word.Visible = $False        
$filename = ($_.fullname).substring(0,($_.FullName).lastindexOf("."))
function saveas-document   {         
        $opendoc = $word.documents.open($doc.FullName);         
    $opendoc.saveas([ref]"$docpath\$filename", [ref]$saveFormat);         
    $opendoc.close();
}       
ForEach ($doc in $srcfiles)     {
    Write-Host "Processing :" $doc.FullName         
    saveas-document        
    $doc = $null   
}   
$word.quit();