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 lluosog yn ffeiliau pdf?

Mae'n hawdd ichi drosi dogfen Word i ffeil PDF gyda'r swyddogaeth Save as in Word. Ond os ydych chi am drosi pob dogfen Word mewn ffolder i wahanu ffeiliau PDF ar unwaith, sut allwch chi ei gyflawni? Bydd yr erthygl hon yn dangos cod VBA i chi swp-drosi dogfennau Word lluosog i ffeiliau pdf yn Word.

Swp trosi dogfennau Word lluosog yn ffeiliau pdf gyda VBA
Swp trosi dogfennau Word lluosog i ffeiliau pdf gyda Kutools for Word


Swp trosi dogfennau Word lluosog yn ffeiliau pdf gyda VBA

Mae'r cod VBA canlynol yn eich helpu i drosi pob dogfen Word mewn ffolder yn ffeiliau pdf ar unwaith. Gwnewch fel a ganlyn.

1. Yn 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 isod god VBA i mewn i ffenestr y Modiwl.

Cod VBA: Swp trosi sawl dogfen Word yn ffeiliau pdf yn Word

Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20181123
    Dim xIndex As String
    Dim xDlg As FileDialog
    Dim xFolder As Variant
    Dim xNewName As String
    Dim xFileName As String
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1) + "\"
    xFileName = Dir(xFolder & "*.*", vbNormal)
    While xFileName <> ""
        If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then
            xIndex = InStr(xFileName, ".") + 1
            xNewName = Replace(xFileName, Mid(xFileName, xIndex), "pdf")
            Documents.Open FileName:=xFolder & xFileName, _
                ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
                PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
                WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
                wdOpenFormatAuto, XMLTransform:=""
            ActiveDocument.ExportAsFixedFormat OutputFileName:=xFolder & xNewName, _
                ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
                wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
                Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
                CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
                BitmapMissingFonts:=True, UseISO19005_1:=False
            ActiveDocument.Close
        End If
        xFileName = Dir()
    Wend
End Sub

3. Gwasgwch y F5 allwedd i redeg y cod.

4. Mae deialog Pori yn ymddangos, dewiswch y ffolder sy'n cynnwys dogfennau Word y byddwch chi'n eu trosi i ffeiliau pdf, a chliciwch ar y OK botwm.

Yna mae'r holl ddogfennau Word mewn ffolder a ddewiswyd yn cael eu trosi'n ffeiliau pdf ar wahân ar unwaith. Gweler y screenshot:


Swp trosi dogfennau Word lluosog i ffeiliau pdf gyda Kutools for Word

Os yw'n anodd trin cod VBA, gallwch roi cynnig ar y Trosi dogfennau cyfleustodau Kutools am Word i ddatrys y broblem.

Kutools am Word : Gyda mwy na 100 o ychwanegion Word defnyddiol, am ddim i geisio heb unrhyw gyfyngiad mewn 60 diwrnod.

1. Cliciwch Kutools Plus > Doc / Docx. Gweler y screenshot:

2. Yn y Troswr Fformat Dogfen ffenestr, mae angen i chi wneud fel a ganlyn:

2.1) Dewiswch y ffolder yn cynnwys dogfennau y byddwch yn eu trosi i pdf yn y Ffolder ffeiliau ffynhonnell adran;
2.2 Dewis Trosi docx i pdf oddi wrth y Trosi Fformat rhestr ostwng;
2.3) Yn ddiofyn, mae'r Llwybr cyrchfan yr un peth â'r ffynhonnell blwch yn cael ei wirio. Os ydych chi am roi'r holl ffeiliau pdf wedi'u trosi yn yr un ffolder, cadwch yr opsiwn hwn wedi'i ddewis;
Os ydych chi am wahanu'r ffeiliau pdf a'r dogfennau ffynhonnell, mae angen i chi ddad-dicio'r Llwybr cyrchfan yr un peth â'r ffynhonnell blwch, a dewis ffolder newydd i gadw'r ffeiliau pdf yn y Cadw i blwch;
2.4) Cliciwch y dechrau botwm. Gweler y screenshot:

3. Yna mae blwch deialog yn ymddangos i ddweud wrthych faint o ddogfennau sydd wedi'u trosi'n llwyddiannus, cliciwch y OK botwm a chau'r Troswr Fformat Dogfen ffenestr.

Nawr mae'r holl ddogfennau fformat .docx yn cael eu trosi'n ffeiliau pdf.

Os ydych chi am gael treial am ddim o'r cyfleustodau hwn, ewch i dadlwythwch y meddalwedd am ddim yn gyntaf, ac yna ewch i gymhwyso'r llawdriniaeth yn ôl y camau uchod.



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.
    Chengchi · 1 months ago
    VBA 很棒!!感謝您的分享。
  • To post as a guest, your comment is unpublished.
    K DEG · 2 months ago
    This saved my day, thanks so much!

    I would just like to point out for people using this, if the Word seems to freeze, just wait - it is generating the .pdf files. My Word froze but I opened the folder of the files, and could see that it was indeed generating the .pdf for all files.
  • To post as a guest, your comment is unpublished.
    Garrie · 2 months ago
    If you change
    xFileName = Dir(xFolder & "*.*", vbNormal)
     to 
    xFileName = Dir(xFolder & "*.doc*", vbNormal)
    the macro will not crash when there are non-Word files in the same folder.

  • To post as a guest, your comment is unpublished.
    Garrie · 2 months ago
    If you change
    xIndex = InStr(xFileName, ".") + 1
     to 
    xIndex = InStrRev(xFileName, ".") + 1
    it will search from the end of the string to find the first period. This will avoid problems where the filename contains periods.
  • To post as a guest, your comment is unpublished.
    Jirka · 3 months ago
    Change
     xIndex = InStr(xFileName, ".") + 1


  • To post as a guest, your comment is unpublished.
    San · 10 months ago
    The VBA code is great. Cheers ,ate
  • To post as a guest, your comment is unpublished.
    Doris · 1 years ago
    thanks for vba code , it helps a lot.
  • To post as a guest, your comment is unpublished.
    Eric Smith · 1 years ago
    Hello, Thank you so much for this code. It is working well, however, I get a dialog box after each conversion to save the word doc and I have to save. Can you include code in the macro to make that save and close the file instead of having to close each one?
    • To post as a guest, your comment is unpublished.
      Rebecca · 10 months ago
      if you add "ActiveDocument.Save" right above "ActiveDocument.Close" it will save the document before closing itself so you don't have to always hit the save prompt.
  • To post as a guest, your comment is unpublished.
    9aks92 · 1 years ago
    Hi,

    I get runtime error '424':
    Object required

    image attached.


    Please help.

    Thanks.
  • To post as a guest, your comment is unpublished.
    Akshay · 1 years ago
    Hi,

    I get runtime error '424':
    Object required

    at the below code

    Documents.Open Filename:=xFolder & xFileName, _
    ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
    PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
    WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
    wdOpenFormatAuto, XMLTransform:=""


    wdOpenFormatAuto = 0 it says.

    Please help.

    Thanks.
  • To post as a guest, your comment is unpublished.
    Stefan · 1 years ago
    Hi there,


    is there an easy way to adjust the VBA Code so that the Documents are convertet to .txt-Files?
  • To post as a guest, your comment is unpublished.
    Sammy · 2 years ago
    Is there any way to have the file name taken from the text of the document?
  • To post as a guest, your comment is unpublished.
    Marzio · 2 years ago
    VBA if i try to convert file that contains macros the macro swith to open file and ends without close file.
  • To post as a guest, your comment is unpublished.
    michaelwaung · 2 years ago
    So nice blog, Thanks for sharing this blog. It Has so useful information for users. I liked this information so much.
    Hope you keep sharing such kind of information convert word doc to html