Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:18:09+00:00 2026-06-15T20:18:09+00:00

I posted this script the other day in an effort to discover a good

  • 0

I posted this script the other day in an effort to discover a good way to change file extensions when “saving as.” I had the problem licked, but as of this morning, the script will not run without errors. Here’s the error message I’m getting:

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

if “16” is the error code, that represents an inability to delete the directory…but it doesn’t appear as if I’m asking for that at all–unless there’s some default parameter in place somewhere. I’m pretty much baffled.anyone have any other ideas I can try out?

$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(); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:18:10+00:00Added an answer on June 15, 2026 at 8:18 pm

    this should do what do you need, but is not the best design 🙂

    $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"); 
    
    $global:word = new-object -comobject word.application 
    
    $word.Visible = $False        
    
    #$filename = ($_.fullname).substring(0,($_.FullName).lastindexOf("."))
    
    function saveas-document ($docs)  {         
        $opendoc = $word.documents.open($docs);    
        $savepath = $docs -replace [regex]::escape($htmPath),"$docpath"
        $savepath = $savepath -replace '\.html*', '.doc'
        $opendoc.saveas([ref]"$savepath", [ref]$saveFormat);         
        $opendoc.close();
    }       
    ForEach ($doc in $srcfiles)     {
        Write-Host "Processing :" $doc.FullName         
        saveas-document  -doc  $doc.FullName     
        $doc = $null   
    }   
    
    $word.quit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried EVERY single script/code/method posted on StackOverflow and other sites for this,
this question is very similar to many other questions posted on stack overflow,I have
I have a pagination script which I have posted below, the problem is I
Can someone explain why the console acts this way? I posted this question once,
In Perl, is there any way to tell which .pl script has initialized this
I posted this question on Reddit Programming and did not get a single response.
I posted this very same item on SERVERFAULT, but got no reply. So here
I posted this back in May on the [android-developers] Google Group. I never heard
I posted this question here on purpose, although - for my case - it
I posted this question on superuser a bit ago, but I haven't gotten an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.