×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Converting all Word Documents to Plain Text(.txt) format in a "Specific" folder

Converting all Word Documents to Plain Text(.txt) format in a "Specific" folder

Converting all Word Documents to Plain Text(.txt) format in a "Specific" folder

(OP)
Hey,

So, I was able to convert one word document to .txt format (See Code below).

CODE -->

Dim objWord, objDoc

Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\VBS\Testing.docx")
objDoc.SaveAs "C:\VBS\Testing.txt", 2
objDoc.Close
objWord.Quit

Set objDoc = Nothing
Set objWord = Nothing

msgbox "Word Document Converted to Text." 

Now, I don't want to specify the Exact name of the word document. I would like the script to identify the word document in a Particular Folder and then convert it to .txt
Here is What I have so far:

CODE -->

Dim objWord, objDoc, objFSO, objFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
Set objFolder = objFSO.GetFolder("C:\VBS\")

For Each objFile In objFolder.Files

Set objDoc = objWord.Documents.Open("C:\VBS\")
objDoc.SaveAs "C:\VBS\", 2
objDoc.Close
objWord.Quit

Set objDoc = Nothing
Set objWord = Nothing
Next

msgbox "Word Document Converted to Text." 

Any help will be greatly appreciated.

RE: Converting all Word Documents to Plain Text(.txt) format in a "Specific" folder

Set objDoc = objWord.Documents.Open(objFile)

Just my $.02

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg

RE: Converting all Word Documents to Plain Text(.txt) format in a "Specific" folder

Wouldn't it be more like:

For Each objFile In objFolder.Files
Set objDoc = objWord.Documents.Open("C:\VBS\"& objFile.Name & "." & objFile.Extension)
objDoc.SaveAs "C:\VBS\" & objFile.Name & ".txt", 2
objDoc.Close
objWord.Quit
Set objDoc = Nothing
Set objWord = Nothing
Next

I can't recall off the top of my head whether objFile.Name returns just the file name (ie: C:\VBS\testing.docx would return "testing") or the file name with file extension (ie: C:\VBS\testing.docx would return "testing.docx") or even the full path with filename and extension, as in "C:\VBS\testing.docx".

You could always comment out all the lines in your For...Next loop and add these lines inside the loop...

WScript.Echo objFile
WScript.Echo objFile.Name
WScript.Echo objFile.Extension

...just to see what you get. Then you'd know which syntax to use for sure.

Good luck!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close