Convert Word Document To PDF With Word VBA

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video i'm going to show you a php script to convert a word document to a pdf file so have a word document file that i want to convert to a pdf file and this file is 17 pages slow now open a blank world document file and save the file as a macro enabled file now i'm going to click on developer tab and click on visual basic to open the fiber window and i'll insert a new module alright so here i'm going to create a subroutine and i'll name the subroutine convert word to pdf i'll start by declaring my variables in objects so the first object i'm going to declare is the word document file and let's name the object dlc as document next i want to create several variables to store a different file path and folder paths all right so this is going to be the file path linked to the word document template i'll name the variable will file path let's stream i also want to create a variable to store just the file name and this one is going to be the folder path we want to save the pdf file and i'll name the variable output path a string all right so for the output path i'm going to simply copy paste the folder path where i want to save the pdf file and make sure that you insert the background slash at the end and for the wall file path variable this one is going to be the file path to the word document and to extract the file name which is this portion right here i'm going to create a function and i'll name the function get file name and we're going to provide a parameter called file path a string and the output is going to be a string there type as well alright so inside the function i'm going to type dmv a sphere this is going to be the temporary variable that i'm going to use and i want to split the file path argument with application the path separator and to get the thumbnail i can type gets file name is equals to b followed by robinson d u bound value from the v object now going back to the convert world to pdf subroutine here i want to create the file name variable by inserting the get file name function and i'll provide all file path as the argument and this will be file all right so at this point we can open the word document using documents that open method and i'll provide the word file path variable and i can save the output as dlc and because this is an option i need to use set statement so when i open the file with this statement here i want to simply save the existing word document as a pdf file and i can do that by referencing the doc object that save us 2. for the file name it's going to be output path concatenate with the file name and because the file name variable still has the dlcx extension type i need to place the extension from the docx to the pdf and for the file format for pdf it's going to be 17. and once i convert the word document to a pdf file i can close the word document and i'm going to set the save changes to false and that's it and this should be nothing all right so going back to the uh template file of the blank document i can run the macro by going to view macros and here's the convert world to pdf macro and wrong oh so we should have a typo this should be worth file path now let me try again all right so it's opening the word document and doing the conversion it looks like the macro is finished and here i'm going to open the pdf file and just to make sure that i have all the contents translated into the pdf file from the word document all right so this is going to be everything i'm going to show you in this video and hopefully you guys found this video useful in the choice thank you guys for watching i'll see you guys in the next video
Info
Channel: Jie Jenn
Views: 9,583
Rating: undefined out of 5
Keywords: Word, Word VBA, PDF, word to pdf, word doc to pdf
Id: Z7HAAHdoD9k
Channel Id: undefined
Length: 6min 10sec (370 seconds)
Published: Sun Mar 13 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.