انتقل إلى المحتوى الرئيسي

كيفية تحويل عدة مستندات Word إلى ملفات PDF دفعة واحدة؟

من السهل عليك تحويل مستند Word إلى ملف PDF باستخدام وظيفة حفظ باسم في Word. ولكن إذا كنت تريد تحويل جميع مستندات Word الموجودة في مجلد إلى ملفات PDF منفصلة مرة واحدة ، فكيف يمكنك تحقيق ذلك؟ ستوضح لك هذه المقالة رمز VBA لتحويل مستندات Word المتعددة إلى ملفات pdf في Word دفعة واحدة.

قم بتحويل مستندات Word متعددة إلى ملفات pdf باستخدام VBA
قم بتحويل مستندات Word متعددة إلى ملفات pdf باستخدام Kutools for Word


قم بتحويل مستندات Word متعددة إلى ملفات pdf باستخدام VBA

يساعدك رمز VBA التالي على تحويل جميع مستندات Word الموجودة في مجلد بسرعة إلى ملفات pdf في وقت واحد. الرجاء القيام بما يلي.

1. في Word ، اضغط على قديم + F11 مفاتيح لفتح ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

2. في ال ميكروسوفت فيسوال باسيك للتطبيقات الإطار، انقر فوق إدراج > وحدة، ثم انسخ رمز VBA أدناه في نافذة الوحدة النمطية.

كود فبا: دفعة تحويل مستندات وورد متعددة إلى ملفات pdf في وورد

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. اضغط على F5 مفتاح لتشغيل الكود.

4. ينبثق مربع حوار "تصفح" ، يرجى تحديد المجلد الذي يحتوي على مستندات Word التي ستحولها إلى ملفات pdf ، ثم انقر فوق OK .

ثم يتم تحويل جميع مستندات Word الموجودة في المجلد المحدد إلى ملفات pdf منفصلة مرة واحدة. انظر لقطة الشاشة:


قم بتحويل مستندات Word متعددة إلى ملفات pdf باستخدام Kutools for Word

إذا كان من الصعب التعامل مع التعليمات البرمجية لـ VBA ، فيمكنك تجربة تحويل المستندات فائدة كوتولس للكلمة لحل المشكلة.

كوتولس للكلمة : مع أكثر من 100 وظيفة إضافية مفيدة لـ Word ، حر في المحاولة دون قيود 60 أيام.

1. انقر كوتولس بلس > Doc / Docx. انظر لقطة الشاشة:

2. في ال محول تنسيق المستند نافذة ، ما عليك القيام به على النحو التالي:

2.1) حدد المجلد الذي يحتوي على المستندات التي ستقوم بتحويلها إلى pdf في مجلد الملف المصدر قسم.
2.2 اختر تحويل docx إلى pdf من تنسيق تحويل قائمة منسدلة؛
2.3) بشكل افتراضي ، فإن ملف مسار الوجهة هو نفس المصدر المربع محددًا. إذا كنت تريد وضع جميع ملفات pdf المحولة في نفس المجلد ، فقط احتفظ بهذا الخيار محددًا ؛
إذا كنت تريد فصل ملفات pdf والمستندات المصدر ، فستحتاج إلى إلغاء تحديد ملف مسار الوجهة هو نفس المصدر ، وحدد مجلدًا جديدًا لحفظ ملفات pdf في ملف حفظ في صندوق؛
شنومكس) انقر فوق آبدأ زر. انظر لقطة الشاشة:

3. ثم ينبثق مربع حوار لإخبارك بعدد المستندات التي تم تحويلها بنجاح ، انقر فوق OK زر وأغلق ملف محول تنسيق المستند نافذة.

يتم الآن تحويل جميع المستندات بتنسيق docx. إلى ملفات pdf.

إذا كنت تريد الحصول على نسخة تجريبية مجانية من هذه الأداة المساعدة ، فيرجى الانتقال إلى تنزيل البرنامج مجانًا اولا ثم انتقل لتطبيق العملية حسب الخطوات اعلاه.

أفضل أدوات إنتاجية المكتب

كوتولس للكلمة - ارفع تجربة كلمتك مع أكثر 100 ميزات رائعة!

🤖 مساعد كوتولس AI: تحويل كتابتك باستخدام الذكاء الاصطناعي - توليد المحتوى  /  إعادة كتابة النص  /  تلخيص المستندات  /  الاستفسار عن المعلومات على أساس الوثيقة، كل ذلك داخل Word

📘 إتقان الوثيقة: تقسيم الصفحات  /  دمج المستندات  /  تصدير التحديد بتنسيقات مختلفة (PDF/TXT/DOC/HTML...)  /  دفعة تحويل إلى PDF  /  تصدير الصفحات كصور  /  طباعة ملفات متعددة في وقت واحد

تحرير المحتويات: بحث واستبدال دفعة عبر ملفات متعددة  /  تغيير حجم كافة الصور  /  تبديل صفوف وأعمدة الجدول  /  تحويل الجدول إلى نص

🧹 تنظيف سهل: اكتساح بعيدا مساحات اضافية  /  فواصل القسم  /  كل الرؤوس  /  مربعات النص  /  الارتباطات التشعبية  / لمزيد من أدوات الإزالة، توجه إلى موقعنا إزالة المجموعة

إدراجات إبداعية: إدراج الف فاصل  /  مربعات الاختيار  /  أزرار الراديو  /  رمز الاستجابة السريعة  /  الباركود  /  جدول الخط القطري  /  شرح المعادلة  /  صورة توضيحية  /  الجدول التوضيحي  /  صور متعددة  / اكتشف المزيد في أدخل المجموعة

🔍 التحديدات الدقيقة: يحدد بدقة صفحات محددة  /  الجداول  /  الأشكال  /  فقرات العناوين  / تحسين التنقل باستخدام الأكثر من ذلك حدد الميزات

تحسينات النجوم: انتقل بسرعة إلى أي مكان  /  الإدراج التلقائي للنص المتكرر  /  التبديل بسلاسة بين نوافذ المستندات  /  11 أدوات التحويل

؟؟؟؟ هل تريد تجربة هذه الميزات؟ يقدم Kutools for Word أ الإصدار التجريبي المجاني من 60 يومًا، بلا حدود! 🚀
 
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