Note: The other languages of the website are Google-translated. Back to English
Vpiši se  \/ 
x
or
x
Registracija  \/ 
x

or

Kako paketno pretvoriti več dokumentov Word v datoteke PDF?

Preprosto pretvorite Wordov dokument v datoteko PDF s funkcijo Shrani kot v Wordu. Če pa želite vse dokumente programa Word v mapi pretvoriti v datoteke PDF naenkrat, kako lahko to dosežete? Ta članek vam bo prikazal kodo VBA za paketno pretvorbo več Wordovih dokumentov v datoteke PDF v Wordu.

Paketno pretvorite več Wordovih dokumentov v datoteke PDF s pomočjo VBA
Paketno pretvorite več dokumentov Word v datoteke PDF s programom Kutools for Word


Paketno pretvorite več Wordovih dokumentov v datoteke PDF s pomočjo VBA

Naslednja koda VBA vam pomaga hitro pretvoriti vse Wordove dokumente v mapi v datoteke PDF naenkrat. Naredite naslednje.

1. V Wordu pritisnite druga + F11 tipke za odpiranje Microsoft Visual Basic za aplikacije okno.

2. V Ljubljani Microsoft Visual Basic za aplikacije okno, kliknite Vstavi > Moduli, nato kopirajte spodnjo kodo VBA v okno modula.

Koda VBA: paketno pretvorite več dokumentov Word v datoteke PDF v programu 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. Pritisnite F5 tipko za zagon kode.

4. Pojavi se pogovorno okno Brskanje, izberite mapo, v kateri so Wordovi dokumenti, ki jih želite pretvoriti v datoteke PDF, in kliknite OK gumb.

Nato se vsi Wordovi dokumenti v izbrani mapi hkrati pretvorijo v ločene datoteke pdf. Oglejte si posnetek zaslona:


Paketno pretvorite več dokumentov Word v datoteke PDF s programom Kutools for Word

Če je s kodo VBA težko ravnati, lahko poskusite Pretvarjanje dokumentov uporabnost Kutools za Word za rešitev problema.

Kutools za Word : Z več kot 100 priročnimi dodatki za Word, brezplačno poskusite brez omejitev v 60 dneh.

1. klik Kutools Plus > Doc / Docx. Oglejte si posnetek zaslona:

2. V Ljubljani Pretvornik oblike dokumenta okno, morate storiti naslednje:

2.1) V mapi izberite mapo z dokumenti, ki jih želite pretvoriti v pdf Mapa izvorne datoteke odsek;
2.2 Izberite Pretvori docx v pdf Iz Pretvori obliko spustni seznam;
2.3) Privzeto je Ciljna pot enaka izvoru polje je označeno. Če želite vse pretvorjene datoteke pdf shraniti v isto mapo, samo izberite to možnost;
Če želite ločiti datoteke pdf in izvorne dokumente, počistite polje Ciljna pot enaka izvoru in izberite novo mapo, da shranite datoteke pdf v Shrani v škatla;
2.4) Kliknite Začetek . Oglejte si posnetek zaslona:

3. Nato se prikaže pogovorno okno, ki vam pove, koliko dokumentov je bilo uspešno pretvorjenih, kliknite OK in zaprite Pretvornik oblike dokumenta okno.

Zdaj se vsi dokumenti v obliki .docx pretvorijo v datoteke pdf.

Če želite brezplačno preskusiti to orodje, pojdite na brezplačno prenesete programsko opremo najprej in nato nadaljujte z uporabo postopka v skladu z zgornjimi koraki.



Priporočena orodja za produktivnost besed

 

Kutools za Word - več kot 100 naprednih funkcij za Word prihranite 50% časa

  • Zapletene in ponavljajoče se operacije je mogoče enkrat obdelati v nekaj sekundah.
  • V Wordov dokument hkrati vstavite več slik v mape.
  • Združite in združite več datotek Word v mapah v eno z želenim vrstnim redom.
  • Trenutni dokument razdelite na ločene dokumente glede na naslov, prelom odseka ali druga merila.
  • Pretvarjanje datotek med dokumenti Doc in Docx, Docx in PDF, zbirka orodij za pogoste pretvorbe in izbiro itd. ...

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