Note: The other languages of the website are Google-translated. Back to English
Mewngofnodi  \/ 
x
or
x
Cofrestru  \/ 
x

or

Sut i swp-drosi dogfennau Word yn ffeil txt?

Mae'r erthygl hon yn sôn am sut i swp-drosi pob dogfen Word mewn ffolder benodol i wahanu ffeiliau TXT yn Word.

Swp trosi dogfennau Word yn ffeiliau txt gyda VBA


Swp trosi dogfennau Word yn ffeiliau txt gyda VBA

Gall y cod VBA isod helpu i drosi'r holl ddogfennau Word mewn ffolder benodol i ffeiliau txt ar unwaith. Gwnewch fel a ganlyn.

1. Yn nogfen Word, pwyswch y Alt + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch Mewnosod > Modiwlau, yna copïwch y cod isod i mewn i ffenestr y Modiwl.

Cod VBA: Swp trosi dogfennau Word yn ffeiliau 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. Gwasgwch y F5 allwedd i redeg y cod.

4. Yn y Pori ffenestr, dewiswch y ffolder yn cynnwys dogfennau Word y byddwch chi'n eu trosi i ffeiliau txt, a chliciwch ar y OK botwm. Gweler y screenshot:

Yna gallwch weld bod yr holl ddogfennau mewn ffolder a ddewiswyd yn cael eu trosi'n ffeiliau txt ar unwaith. Gweler y screenshot:



Offer Cynhyrchedd Geiriau a Argymhellir

 

Kutools For Word - Mwy na 100 o Nodweddion Uwch ar gyfer Word, Arbedwch Eich Amser 50%

  • Gellir gwneud gweithrediadau cymhleth ac ailadroddus brosesu un-amser mewn eiliadau.
  • Mewnosodwch ddelweddau lluosog ar draws ffolderau yn nogfen Word ar unwaith.
  • Uno a chyfuno ffeiliau Word lluosog ar draws ffolderau yn un gyda'r drefn a ddymunir gennych.
  • Rhannwch y ddogfen gyfredol yn ddogfennau ar wahân yn ôl pennawd, toriad adran neu feini prawf eraill.
  • Trosi ffeiliau rhwng Doc a Docx, Docx a PDF, casglu offer ar gyfer trawsnewid a dewis cyffredin, ac ati ...

Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Mina · 3 months ago
    Not working for me, any ideas why?
    Do I need to do this in a word document from the same folder I want to convert or any new word document that I start? -Tried both options and none is working but I am also not getting any error messages

    • To post as a guest, your comment is unpublished.
      mIk · 3 months ago
      Change xFileStr = Dir(xFolder & "\*.doc") to xFileStr = Dir(xFolder & "\*.docx") as i assume you have newer word files format.
    • To post as a guest, your comment is unpublished.
      Mina · 3 months ago
      I'm using windows 10 and Microsoft office 2016
  • To post as a guest, your comment is unpublished.
    DebSutter · 4 months ago
    Thank you! This is extremely helpful
    • To post as a guest, your comment is unpublished.
      Mina · 3 months ago
      How did you get it to work?
  • To post as a guest, your comment is unpublished.
    Mario · 1 years ago
    I'm a fan of poetry. I needed to convert more than 700 word compositions to txt. Thanks to your subroutine I managed to do it in no time.
    Thank you