Nicole Marie
New Member
- Joined
- Apr 13, 2018
- Messages
- 7
Hello!
We are taking a lot of time to manually convert different file types to PDF to be uploaded into an imaging system. I have this code to convert .doc to .pdf, and it's working:
However, sometimes it doesn't convert the first .doc file in the folder. Any idea why?
In addition, how can I modify this code to convert .JPG to .PDF? I've done a lot of searching and I've found a couple (where the code inserts the picture into an excel doc and then saves it as PDF) but I need it to go in and find all the .jpgs in a given folder, like the one above, and convert. Lastly, can I incorporate that into the existing code (which I currently have in Word VBA), or would I have to make a new one? Would it exist in Word, or would I have to put that one in Excel? I am very new to VBA and am trying to learn (I've been searching forums and even checked out a book at the library to help me understand/help me read the coding), so any help for this newbie is truly appreciated!
Thank you.
We are taking a lot of time to manually convert different file types to PDF to be uploaded into an imaging system. I have this code to convert .doc to .pdf, and it's working:
Code:
[FONT=courier new]Sub WordtoPDF()[/FONT]
[FONT=courier new]Application.ScreenUpdating = False[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new]Dim file[/FONT]
[FONT=courier new]Dim path As String[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new]path = "U:\Documents\File Conversion Test"[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new]file = Dir(path & "*.doc") 'Dir means directory[/FONT]
[FONT=courier new]Do While file <> "" '<> means not equal, so this says if the file name isn't blank[/FONT]
[FONT=courier new]Documents.Open FileName:=path & file 'Open files that are located in this directory, ending in .doc[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new] ActiveDocument.ExportAsFixedFormat OutputFileName:= _[/FONT]
[FONT=courier new] file & ".pdf", _[/FONT]
[FONT=courier new] ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _[/FONT]
[FONT=courier new] wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _[/FONT]
[FONT=courier new] Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _[/FONT]
[FONT=courier new] CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _[/FONT]
[FONT=courier new] BitmapMissingFonts:=True, UseISO19005_1:=False[/FONT]
[FONT=courier new] ChangeFileOpenDirectory "U:\Documents\File Conversion Test"[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new]ActiveDocument.Save 'Save active doc[/FONT]
[FONT=courier new]ActiveDocument.Close 'Close active doc[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new]file = Dir()[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new]Loop[/FONT]
[FONT=courier new]
[/FONT]
[FONT=courier new]Application.ScreenUpdating = True[/FONT]
[FONT=courier new]End Sub[/FONT]
However, sometimes it doesn't convert the first .doc file in the folder. Any idea why?
In addition, how can I modify this code to convert .JPG to .PDF? I've done a lot of searching and I've found a couple (where the code inserts the picture into an excel doc and then saves it as PDF) but I need it to go in and find all the .jpgs in a given folder, like the one above, and convert. Lastly, can I incorporate that into the existing code (which I currently have in Word VBA), or would I have to make a new one? Would it exist in Word, or would I have to put that one in Excel? I am very new to VBA and am trying to learn (I've been searching forums and even checked out a book at the library to help me understand/help me read the coding), so any help for this newbie is truly appreciated!
Thank you.
Last edited by a moderator: