My goal for this project is to have this script perform the following:
1- pop a dialogue asking for a working directory to process
2- create a “text” subdirectory
3- open up a word file, run a word macro on the file, and save it as a text file using the same original filename as the word document
4- Repeat step 3 throughout the entire contents of the directory
So far I have step 3 figured out and tested, save the file naming, which I thought was going to be the hardest part to figure out (getting the word macro to run invisibly) but it runs great.
I’ve been self teaching python the past few weeks, and hit a wall trying to get the word macro to fire off, tried it in a VBS and bam, worked right off the bat. But I have no idea how to make this recursive through the entire directory, or take in original filenames with a variable and rename with the same variable. I realize some of these are basic questions and apologize for that – referring me to documentation to help me learn is absolutely fine here. My code for this is pasted below for reference to see what I am doing.
Any help in getting it to process the entire directory and keeping the filenames the same (IE document.doc or .docx becomes document.txt) would be fantastic!
Thanks for any and all pointers!
—
Dim AppWord
Dim OpenDocument
Const docTXT = 2
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = False
Set OpenDocument = AppWord.Documents.Open("C:\test\doc.docx")
AppWord.Run "macro1"
OpenDocument.SaveAs "C:\test\text\docnowtext", docTXT
OpenDocument.Close
Set OpenDocument = Nothing
AppWord.Quit
Set AppWord = Nothing
MsgBox "All done!"
the key to making this work is you need to:
InputBoxDefine aSuborFunctionthat recursively calls itself.docxfile you process itWhenever you encounter aSubfolderyou use it for recursionFor example: