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 8248597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:14:27+00:00 2026-06-07T23:14:27+00:00

I have the following code: Sub WordtoTxtwLB() ‘ ‘ WordtoTxtwLB Macro ‘ ‘ Dim

  • 0

I have the following code:

Sub WordtoTxtwLB()
'
' WordtoTxtwLB Macro
'
'
Dim fileName As String
myFileName = ActiveDocument.Name

ActiveDocument.SaveAs2 fileName:= _
"\\FILE\" & myFileName & ".txt", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=True, AllowSubstitutions:=False, _
LineEnding:=wdCRLF, CompatibilityMode:=0


End Sub

I want to loop this sub through all of the word (.doc) files in a directory. I have the following code:

Sub LoopDirectory()

vDirectory = "C:\programs2\test"

vFile = Dir(vDirectory & "\" & "*.*")

Do While vFile <> ""

Documents.Open fileName:=vDirectory & "\" & vFile

ActiveDocument.WordtoTxtwLB

vFile = Dir
Loop

End Sub

But it is not working. How do I get this to work either by altering the current code or using new code?

  • 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-07T23:14:28+00:00Added an answer on June 7, 2026 at 11:14 pm

    You don’t actually need the WordtoTxtwLB Macro. You can combine both the codes. see this example

    Sub LoopDirectory()
        Dim vDirectory As String
        Dim oDoc As Document
        
        vDirectory = "C:\programs2\test\"
    
        vFile = Dir(vDirectory & "*.*")
    
        Do While vFile <> ""
            Set oDoc = Documents.Open(fileName:=vDirectory & vFile)
            
            ActiveDocument.SaveAs2 fileName:="\\FILE\" & oDoc.Name & ".txt", _
                                   FileFormat:=wdFormatText, _
                                   LockComments:=False, _
                                   Password:="", _
                                   AddToRecentFiles:=True, _
                                   WritePassword:="", _
                                   ReadOnlyRecommended:=False, _
                                   EmbedTrueTypeFonts:=False, _
                                   SaveNativePictureFormat:=False, _
                                   SaveFormsData:=False, _
                                   SaveAsAOCELetter:=False, _
                                   Encoding:=1252, _
                                   InsertLineBreaks:=True, _
                                   AllowSubstitutions:=False, _
                                   LineEnding:=wdCRLF, _
                                   CompatibilityMode:=0
    
            oDoc.Close SaveChanges:=False
            vFile = Dir
        Loop
    End Sub
    

    BTW, are you sure you want to use the *.* wildcard? What if there are Autocad files in the folder? Also ActiveDocument.Name will give you the file name with the Extension.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: <TestMethod()> _ Public Sub GetDirectoryEntryTest() Dim path As String
I have the following code: Private Sub SortWorksheet(ByVal sheet As Worksheet) Dim sStartColumn Dim
I have the following code in my Global.asax file: Protected Sub Application_PreRequestHandlerExecute(sender As Object,
I have the following code in MS Access: Sub IdentityFail() Dim db1 As DAO.Database,
I have the following code : Imports System.Data.OleDb Private Sub getData() Dim connStr As
I have the following code : sub run_query { my $name = shift ||
I have the following VBA code Private Sub CreateQuery_Click() Dim doc As Document Dim
Let's say I have the following code: Sub TestRangeLoop() Dim rng As Range Set
I have the following code that returns 50 random color-coded numbers: Sub RandomNumberColor() Dim
i have the following code: Private Sub TxtPStof_KeyPress(ByVal sender As System.Object, ByVal e As

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.