Skip i'r prif gynnwys

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 ar gyfer 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 ar gyfer 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, rhydd i geisio heb unrhyw gyfyngiad yn 60 diwrnod.

1. Cliciwch Kutools Byd Gwaith > 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 Cynhyrchiant Swyddfa Gorau

Kutools am Word - Dyrchafu Eich Profiad Word gyda Dros 100 Nodweddion Rhyfeddol!

🤖 Cynorthwy-ydd Kutools AI: Trawsnewidiwch eich ysgrifennu gydag AI - Cynhyrchu Cynnwys  /  Ailysgrifennu Testun  /  Crynhoi Dogfennau  /  Ymholwch am Wybodaeth yn seiliedig ar Ddogfen, i gyd o fewn Word

📘 Meistrolaeth Dogfen: Tudalennau Hollti  /  Uno Dogfennau  /  Dewis Allforio mewn Fformatau Amrywiol (PDF/TXT/DOC/HTML...)  /  Trosi swp i PDF  /  Allforio Tudalennau fel Delweddau  /  Argraffu Ffeiliau Lluosog ar unwaith...

Golygu Cynnwys: Swp Dod o Hyd i ac Amnewid ar draws Ffeiliau Lluosog  /  Newid Maint Pob Llun  /  Trawsosod Rhesi Bwrdd a Cholofnau  /  Trosi Tabl i Testun...

🧹 Ymdrech Glân: swap i ffwrdd Mannau Ychwanegol  /  Toriadau Adran  /  Pob Pennawd  /  Blychau Testun  /  hypergysylltiadau  / Am fwy o offer tynnu, ewch i'n Dileu Grŵp...

Mewnosodiadau Creadigol: mewnosod Mil o Wahanwyr  /  Blychau Gwirio  /  Botymau Radio  /  Cod QR  /  Cod Bar  /  Tabl Llinell Lletraws  /  Pennawd Hafaliad  /  Capsiwn Delwedd  /  Pennawd Tabl  /  Lluniau Lluosog  / Darganfod mwy yn y Mewnosod Grŵp...

🔍 Detholiadau Manwl: pinbwynt tudalennau penodol  /  tablau  /  siapiau  /  paragraffau pennawd  / Gwella llywio gyda mwy Dewiswch nodweddion...

Gwelliannau Seren: Llywiwch yn gyflym i unrhyw leoliad  /  auto-mewnosod testun ailadroddus  /  toglo'n ddi-dor rhwng ffenestri dogfennau  /  11 Offer Trosi...

???? Eisiau rhoi cynnig ar y nodweddion hyn? Mae Kutools ar gyfer Word yn cynnig a Treial am ddim 60-dydd, heb unrhyw gyfyngiadau! 🚀
 
Comments (36)
Rated 5 out of 5 · 3 ratings
This comment was minimized by the moderator on the site
Just found this, very helpful. Also thanks for the suggested mods above. I am struggling with the following:

If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") Then


It seems to ask to do the conversion if it's not a doc or docx? (Leaving aside that, I think, for docx it should be last 5 chars, not 4?) Anyway,
This comment was minimized by the moderator on the site
the code stopped. I clicked debug. code below was highlighed yellow

Please, any assistance? thank you

Documents.Open Filename:=xFolder & xFileName, _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, XMLTransform:=""
This comment was minimized by the moderator on the site
Thank you for this. It has just saved me so much time and provided education. I will peruse your site for more top tips.
Thank you again. Brilliant quick fix. One does have to ask, why do MS make such things so impossible to find in their products.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Здравствуйте! Огромное спасибо за модуль! Но есть проблема, у меня куча папок и в каждой папке больше двухсот файлов с разными именами.. Можно ли сделать так чтобы ваш модуль сохранял файлы в PDF не под номерами 1,2,3... и т.д, а под своими собственными именами файлов!? Помогите пожалуйста, и я буду молиться за вас ВЕЧНО!!))
This comment was minimized by the moderator on the site
Hi Егор,
I don't quite understand your question. After converting the file using the VBA code, the name of the PDF file is the same as the name of the Word file.
This comment was minimized by the moderator on the site
Здравствуйте! Большое спасибо вам, за то что вы есть! Спасибо за код он почти идеальный, но ОЧЕНЬ прошу Вас помочь с одним нюансом... Мне Очень важно чтоб ваш макрос сохранял в PDF не под номерами 1.2.3 и т.д, а брал название вордовского файла и сохранял под ним. У меня сто папок и в каждой по 251 файл со своим собственным названием... Мне это Очень нужно, пожалуйста помогите!?????.....
This comment was minimized by the moderator on the site
The VBA macro worked like a charm! :D
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi Myles,
Thank you for your feedback.
This comment was minimized by the moderator on the site
Hello is there a way to select a different output folder and not the original folder?

thank you
This comment was minimized by the moderator on the site
Hi Vincent,
Please try the following VBA code. After running the code, an Open window pops up, please select a folder containing the douments you want to convert, in the second popping up Save PDF files in window, select a folder to save the PDF files.

Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20220805
  Dim xIndex As String
  Dim xDlg As FileDialog, xSaveDlg As FileDialog
  Dim xFolder As Variant, xSaveFolder As Variant
  Dim xNewName As String
  Dim xFileName As String
  On Error Resume Next
  Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
  xDlg.Title = "Open"
  xDlg.ButtonName = "Open"
  If xDlg.Show <> -1 Then Exit Sub
  xFolder = xDlg.SelectedItems(1) + "\"
  xFileName = Dir(xFolder & "*.*", vbNormal)
  Set xSaveDlg = Application.FileDialog(msoFileDialogFolderPicker)
  xSaveDlg.Title = "Save PDF files in"
  xSaveDlg.ButtonName = "Save"
  If xSaveDlg.Show <> -1 Then Exit Sub
  xSaveFolder = xSaveDlg.SelectedItems(1) + "\"
  Application.DisplayAlerts = wdAlertsNone
  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:=xSaveFolder & 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 wdSaveChanges
      End If
      xFileName = Dir()
  Wend
  Application.DisplayAlerts = wdAlertsAll
  Set xDlg = Nothing
  Set xSaveDlg = Nothing
End Sub
This comment was minimized by the moderator on the site
The code does not convert my Word files
This comment was minimized by the moderator on the site
This code is amazing and fast but if there is a link in the Doc file it will open a window stating there may be information linked to another file apply these changes? and then another asking to save as. Is there a way to add to the code to automatically do these steps for me? Out of ~800 there are ~40 and I must be present and do this every time.
thank you
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi Vincent,
The following VBA code can do you a favor. Please give it a try. Thank you for your feedback.

Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20220805
  Dim xIndex As String
  Dim xDlg As FileDialog
  Dim xFolder As Variant
  Dim xNewName As String
  Dim xFileName As String
  On Error Resume Next
  Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
  If xDlg.Show <> -1 Then Exit Sub
  xFolder = xDlg.SelectedItems(1) + "\"
  xFileName = Dir(xFolder & "*.*", vbNormal)
  Application.DisplayAlerts = wdAlertsNone
  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 wdSaveChanges
      End If
      xFileName = Dir()
  Wend
  Application.DisplayAlerts = wdAlertsAll
End Sub
This comment was minimized by the moderator on the site
Вот тут во втором условии надо 4 заменить на 5:
If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 5) <> ".docx") Then
Для исключения проблемы наличия точек можно сделать так:
xIndex = InStr(xFileName, ".doc") + 1
Ну и про советы других товарищей не забыть ;)

This comment was minimized by the moderator on the site
Thank you so much! Saved me so much time!
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