मुख्य सामग्री पर जाएं

Word दस्तावेज़ों को txt फ़ाइल में बैच कैसे बदलें?

लेखक: सिलुविया अंतिम संशोधित: 2018-11-23

यह आलेख इस बारे में बात कर रहा है कि Word में TXT फ़ाइलों को अलग करने के लिए सभी Word दस्तावेज़ों को एक विशिष्ट फ़ोल्डर में बैच में कैसे परिवर्तित किया जाए।

बैच VBA के साथ Word दस्तावेज़ों को txt फ़ाइलों में परिवर्तित करता है


बैच VBA के साथ Word दस्तावेज़ों को txt फ़ाइलों में परिवर्तित करता है

नीचे दिया गया VBA कोड एक विशिष्ट फ़ोल्डर में सभी Word दस्तावेज़ों को एक ही बार में txt फ़ाइलों में परिवर्तित करने में मदद कर सकता है। कृपया निम्नानुसार करें.

1. Word दस्तावेज़ में, दबाएँ ऑल्ट + F11 कुंजी को खोलने के लिए अनुप्रयोगों के लिए माइक्रोसॉफ्ट विज़ुअल बेसिक खिड़की.

2। में अनुप्रयोगों के लिए माइक्रोसॉफ्ट विज़ुअल बेसिक खिड़की, क्लिक करें सम्मिलित करें > मॉड्यूल, फिर नीचे दिए गए कोड को मॉड्यूल विंडो में कॉपी करें।

VBA कोड: बैच Word दस्तावेज़ों को txt फ़ाइलों में परिवर्तित करता है

Sub ConvertDocumentsToTxt()
'Updated by Extendoffice 20181123
    Dim xIndex As Long
    Dim xFolder As Variant
    Dim xFileStr As String
    Dim xFilePath As String
    Dim xDlg As FileDialog
    Dim xActPath As String
    Dim xDoc As Document
    Application.ScreenUpdating = False
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1)
    xFileStr = Dir(xFolder & "\*.doc")
    xActPath = ActiveDocument.Path
    While xFileStr <> ""
        xFilePath = xFolder & "\" & xFileStr
        If xFilePath <> xActPath Then
            Set xDoc = Documents.Open(xFilePath, AddToRecentFiles:=False, Visible:=False)
            xIndex = InStrRev(xFilePath, ".")
            Debug.Print Left(xFilePath, xIndex - 1) & ".txt"
            xDoc.SaveAs Left(xFilePath, xIndex - 1) & ".txt", FileFormat:=wdFormatText, AddToRecentFiles:=False
            xDoc.Close True
        End If
        xFileStr = Dir()
    Wend
    Application.ScreenUpdating = True
End Sub

3। दबाएं F5 कोड चलाने की कुंजी.

4। में ब्राउज विंडो, उस फ़ोल्डर का चयन करें जिसमें Word दस्तावेज़ हैं जिन्हें आप txt फ़ाइलों में कनवर्ट करेंगे, और क्लिक करें OK बटन। स्क्रीनशॉट देखें:

फिर आप देख सकते हैं कि चयनित फ़ोल्डर के सभी दस्तावेज़ एक ही बार में txt फ़ाइलों में परिवर्तित हो गए हैं। स्क्रीनशॉट देखें:

सर्वोत्तम कार्यालय उत्पादकता उपकरण

वर्ड के लिए कुटूल - ओवर के साथ अपने शब्द अनुभव को उन्नत करें 100 उल्लेखनीय विशेषताएं!

🤖 कुटूल्स एआई असिस्टेंट: एआई के साथ अपना लेखन बदलें - सामग्री उत्पन्न करें  /  पाठ पुनः लिखें  /  दस्तावेज़ों को सारांशित करें  /  जानकारी के लिए पूछताछ करें दस्तावेज़ पर आधारित, सभी वर्ड के भीतर

📘 दस्तावेज़ महारत: पन्ने विभाजित करें  /  दस्तावेज़ मर्ज करें  /  विभिन्न प्रारूपों में निर्यात चयन (पीडीएफ/टीएक्सटी/डीओसी/एचटीएमएल...)  /  बैच को पीडीएफ में कनवर्ट करें  /  पेजों को छवियों के रूप में निर्यात करें  /  एक साथ अनेक फ़ाइलें प्रिंट करें...

सामग्री संपादन: बैच ढूंढें और बदलें अनेक फ़ाइलों में  /  सभी चित्रों का आकार बदलें  /  तालिका पंक्तियों और स्तंभों को स्थानांतरित करें  /  तालिका को पाठ में बदलें...

🧹 सहज स्वच्छ: साफ़ कर दो अतिरिक्त स्थान  /  अनुभाग टूट जाता है  /  सभी शीर्षलेख  /  पाठ बक्से  /  हाइपरलिंक  / अधिक हटाने वाले टूल के लिए, यहां जाएं समूह हटाएँ...

रचनात्मक निवेशन: डालें हजार विभाजक  /  चेक बॉक्स  /  रेडियो बटन  /  क्यूआर कोड  /  बारकोड  /  विकर्ण रेखा तालिका  /  समीकरण कैप्शन  /  तस्वीर का शीर्षक  /  सारणी का शीर्षक  /  एकाधिक चित्र  / में और अधिक खोजें समूह सम्मिलित करें...

🔍 परिशुद्धता चयन: सटीक विशिष्ट पृष्ठ  /  टेबल्स  /  आकृतियाँ  /  शीर्षक पैराग्राफ  / के साथ नेविगेशन बढ़ाएँ अधिक सुविधाएँ चुनें...

स्टार संवर्द्धन: किसी भी स्थान पर नेविगेट करें  /  दोहरावदार पाठ स्वतः सम्मिलित करें  /  दस्तावेज़ विंडोज़ के बीच टॉगल करें  /  11 रूपांतरण उपकरण...

👉 क्या आप इन सुविधाओं को आज़माना चाहते हैं? वर्ड के लिए कुटूल्स एक ऑफर करता है 60- दिन का नि: शुल्क परीक्षण, बिना किसी सीमा के! 🚀
 
Comments (22)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Vielen Dank, das ist wirklich sehr hilfreich! Ich werde auf Deine Seite bei der nächsten Gelegenheit verweisen.
Gruß
Uli
This comment was minimized by the moderator on the site
Hi, this works perfectly. Is there a way to choose a different encoding format of the TXT (UTF-8 instead of Windows for example) ?
This comment was minimized by the moderator on the site
Hi Simon,
The following VBA code helps to convert all Word documents in a specified folder to UTF-8 .txt files
Sub ConvertDocumentsToTxt()
'Updated by Extendoffice 20201031
    Dim xIndex As Long
    Dim xFolder As Variant
    Dim xFileStr As String
    Dim xFilePath As String
    Dim xDlg As FileDialog
    Dim xActPath As String
    Dim xDoc As Document
    Application.ScreenUpdating = False
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1)
    xFileStr = Dir(xFolder & "\*.doc")
    xActPath = ActiveDocument.Path
    While xFileStr <> ""
        xFilePath = xFolder & "\" & xFileStr
        If xFilePath <> xActPath Then
            Set xDoc = Documents.Open(xFilePath, AddToRecentFiles:=False, Visible:=False)
            xIndex = InStrRev(xFilePath, ".")
            xDoc.SaveAs Left(xFilePath, xIndex - 1) & ".txt", FileFormat:=wdFormatText, AddToRecentFiles:=False, Encoding:=msoEncodingUTF8
            xDoc.Close True
        End If
        xFileStr = Dir()
    Wend
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Merci beaucoup ! La conversion se fait très bien
This comment was minimized by the moderator on the site
Many thanks
This comment was minimized by the moderator on the site
Hello, Thank you for this post. When I hit "run", I get an error message:"Compile Error: Invalid Outside Procedure." This is whether I use the doc or the docx extension (maybe unrelated but I tried both.) Please can you help? I have no idea how to use code.... and really need to convert a ton of docs. Thank you!
This comment was minimized by the moderator on the site
Hi Durga,
The code works well in my case.
Please make sure that the Module (Code) window contains only the VBA code provided in the post.
This comment was minimized by the moderator on the site
That worked a treat! Thanks!
Rated 5 out of 5
This comment was minimized by the moderator on the site
I NEED them to convert to delimited text files is this possible still.
This comment was minimized by the moderator on the site
I used the script above to batch convert documents in Korean, but the script did not work. When I tired to change the encoding, Can anyone help me with this error?
This comment was minimized by the moderator on the site
Thanks for this - I was just going to code something myself when I thought, "Hey perhaps someone has done this already?" You had, and a deal more elegantly than I would have done. Thanks you for your hard work.
This comment was minimized by the moderator on the site
The script works great for me, but only for one folder. Is there any way to include all subfolders?
This comment was minimized by the moderator on the site
Thank you a lot! Worked like a charm!
This comment was minimized by the moderator on the site
Worked rapidly and perfectly on a folder full of .docx files. I thank you/
This comment was minimized by the moderator on the site
Hi, the code works but at the end gives me 'Runtime error 91', some of my files have objects. Any idea how can I fix this?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations