Using a Word VB script to save as TXT with HTML extension

M

Mike

OK, here's the issue:

I'm working on a project, and I'm using Word to set up the HTML. That
is, each Word doc has the HTML code necessary for the page. I'm using
color coding for certain sections and graying out portions of code
that I don't need to see.

What I want to do is run a VB script that will save the existing file
as a TEXT file but with an HTM extension using the existing name of
the DOC file.

I don't want it to save as an HTML file. I don't want to go through
the "File" "Save As ..." menu system. Although if I have to do it, I
will.

I have 130 files to process, and if I need to make global changes,
then I can simply open the files and run a search-and-replace script
on the original Word docs and re-save as TXT with HTM extension.
That's the reason for setting up as Word docs.

Example:
Word DOC: profile-harrison.doc
Want to output to: profile-harrison.htm (but saving as TXT)

Any thoughts?

Thanks,

-Mike
 
C

Chad DeMeyer

Mike,
Assuming your script gets a handle on the doc something like "oDoc =
oWord.Documents.Open("Somefile.doc"), from there you can add something like
this:

With oDoc
.SaveAs "Somefile.txt", [Text=2, TextLineBreaks=3, UnicodeText=7]
.Close
End With
'May want to add code here to test whether Word has finished closing the
document
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.GetFile("[path]\Somefile.txt")
oFile.Name = "Somefile.htm"
Set oFile = Nothing
Set fso = Nothing

Hope that helps
Regards,
Chad
 
A

Alan Silver

Mike said:
I have 130 files to process, and if I need to make global changes, then
I can simply open the files and run a search-and-replace script on the
original Word docs and re-save as TXT with HTM extension. That's the
reason for setting up as Word docs.

Seems like overkill to me. Get a decent text editor and you can do this
without any coding. Many text editors come with a search and replace
facility that will work over multiple files.

Failing that, there are loads of free and cheap utilities that will do
this for you. Clean fast and much easier than writing your own code.

HTH
 
M

Mike

Hey Chad -- thanks a lot. Very much appreciated. Alan -- I'll keep
your suggestion in mind.

Regards,

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top