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

  • Home
  • SEARCH
  • 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 7431747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:20:37+00:00 2026-05-29T09:20:37+00:00

My goal for this project is to have this script perform the following: 1-

  • 0

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!"
  • 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-05-29T09:20:38+00:00Added an answer on May 29, 2026 at 9:20 am

    the key to making this work is you need to:

    • You need to prompt the user, perhaps with InputBox
    • You can generate filename.txt from filename.docx by doing a Replace on the extension
    • Define a Sub or Function that recursively calls itself
    • Implement using FileSystemObject, File and Folder objects
    • Whenever you encounter a .docx file you process it
    • Whenever you encounter a Subfolder you use it for recursion
    • Added support for both .doc and .docx files

    For example:

    Option Explicit  
    
    Sub DoSomethingWithDOCX(docxpath)
        Dim fso, file, folder, txtpath
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set file = fso.GetFile(docxpath)
        Set folder = file.ParentFolder
        If Not fso.FolderExists(folder + "\text") Then
            Call fso.CreateFolder(folder + "\text")
        End If
        If Right(file.Name, 5) = ".docx" Then
            txtpath = folder & "\text" & "\" & Replace(file.Name, ".docx", ".txt")
        ElseIf Right(file.Name, 4) = ".doc" Then
            txtpath = folder & "\text" & "\" & Replace(file.Name, ".doc", ".txt")
        End If
    
        ' @@TODO: Do your original code with docxpath and txtpath
    End Sub
    
    Sub SearchForDOCX(path)
        Dim fso, file, folder, subfolder, txt
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set folder = fso.GetFolder(path)
        For Each file in folder.Files
            If right(file.Name, 5) = ".docx" Then
                Call DoSomethingWithDOCX(path + "\" + file.Name)
            ElseIf right(file.Name, 4) = ".doc" Then
                Call DoSomethingWithDOCX(path + "\" + file.Name)
            End If
        Next
        'For Each subfolder in folder.SubFOlders
        '    Call SearchForDOCX(subfolder.Path)
        'Next
    End Sub
    
    Dim path
    path = InputBox("Specify Folder to process")
    Call SearchForDOCX(path)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this project I'm working on. The following conditions apply In this project
My goal is to have the url routing as following: http://www.abc.com/this-is-peter-page http://www.abc.com/this-is-john-page What is
Hey all, i've been working on this small project in XNA the goal is
The end goal of this part of my project is to be able to
my goal is if I have this: colmuns c1 | c2 | c3 |
Here's my ultimate goal in all of this. I have a viewcontroller with a
I have data like this: Team | goal a | 5 b | 8
I have this function. And its goal is to take the last character first
The ultimate goal of this project is to send low level input (so that
I have a standard 800x600 window in my XNA project. My goal is to

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.