Real-life Word App Automation Using VBA. Read/write to Word Document, Publish, Print and more

Real-life Word App Automation Using VBA. Read/write to Word Document, Publish, Print and more Hey guys welcome back to vbe A to Z I'm long to my and in this video we'll create a small project to update Word document using Excel data in nutshell this video is going to show you how to.

Real-life Word App Automation Using VBA. Read/write to Word Document, Publish, Print and more

Integrate Excel and Word document using VBA well understand object model and learn how to read and write 2d subjects as always project files and source codes are free for download and use the only.

Request from you is to support my channel so I can keep sharing all this useful videos so before we begin please do not forget to subscribe and hit the bell icon for upcoming videos in the.

Essence of time will create a simple UI which the program will use to read the user input and update the word document so here we have you know a sample of the list agreement that we'll be using for.

This demonstration so the idea here is to you know I write a small program to add the contract the landlord's name the tenants name and fill this additional address and so on and then we're going.

To print it out to PDF where you can write a print comment as well from Excel okay so first we'll have to add you know like a placeholder for all this as a bookmark.

And then we're gonna you know like write a program to read this read and write to these spaces okay so first let me add you know like this will be the country did so in order to.

Access the bookmark go to insert and then under links you should bring up this bookmark here else let's say country date this this is more like if you're familiar with Excel named rings.

This is more like that that okay so see date and then we'll call this this will be landlord and then it's gonna be the name of the tenant.

Okay so for now we'll just add this tree and I'll just save the document okay this document is saving this folder here now I'm gonna bring up the visual editor it just ignore this so before we.

Go here let's look at the object model very quickly so this is from the word you know like object model overview so here if you look here application is where we are at the moment and then the.

Document bookmark and then the range this is how in a way all of you know like so many objects these are you know like summarize of it some of the useful ones so let me give you an example so.

Posts Related:

    Document bookmark and then green okay so

    If you have to refer to this book Martha we just added the way to do that it's gonna be to phrase onto this or active document dot name will give us the name.

    Of this file right so from this document let's say that and then bookmarks if we print out the bookmark name like this is gonna give a city that's the first bookmark so it's it exists or you can.

    Also say dot value or tags dot range dot thanks is equal to and let's see March 29 2020 okay okay sorry so it writes the value there okay this is how you can write to these dis ranges.

    Okay I'm gonna do control Z so if I ate press f5 and go to bookmark the you know I bookmark is still intact okay now you can also programmatically add the range the bookmark okay for example let's say.

    We want to do that to this selection here let's say we want to add a name or let's say this one okay let's say this is the address and then here bookmarks dot add then here you can specify the.

    Name address one and then this could be selection dot range okay so if I go here now the bookmark and this is address one so if I hit go to so the address one has been added successfully so this is how.

    You can you know like navigate to the bookmark at the bookmark and so on okay so now let's go ahead and design a small user interface I'm gonna go and close this for now.

    Now I didn't have a new excel so I'm not gonna waste too much time on this one you okay so this should be all from the UI design perspective here I put a name.

    Range for the word but the output part for now we're gonna include only this field so contract a tenant landlord and the address line one right all these are named rains now so.

    We'll start writing the code now to

    Export this okay I'm gonna quickly add plant for the word document again all this will be available for download.

    Just check the video description and let's see that every time this is created we want to see the backup as a PDF so we call this output I'm gonna see the file here okay so so first I'll add.

    This date and then let's say that the tenant is again will this use same name to be consistent and then let's say oops let's say this is and then let's see that I'm the tenant like this and this.

    Address could be any address let's say 52nd Street in New York City and then okay so let's say this is a sample that we have now now I'm gonna bring up my visual basic editor.

    Okay so let's call this export to toward okay so before we can export we'll have to add a reference to the word document we'll do the early binding look for Microsoft Word object library this one.

    And check the box click on OK first let's declare the application for a word no team okay and then next will be the document as and then will have will have a range.

    A sound okay so this is gonna be range let's call this contract date and then second is gonna be the tenant landlord and the address line okay and then we'll be clear the path so.

    I the document path will be the string and then export but it's also gonna be the string okay so let's try to open the word document first so here you specify the pot that will be this so let us say.

    This dot thanks and let's open and read-only so read-only will be true yeah so for now I'm just gonna leave it as it is maybe if we want to print it out we can export this document as fix format.

    As well to PDF and the output part will be like this this is where we want to save the output so this is just a part and then we'll save this as let's say the tenant name the file name of the.

    Savior is gonna name dot PDF this hard code is for now gangsta here's the PDF is exported ok well now before that for now I'll just reorganize this a bit here we can see.

    Out file pod a string all we can say it is recorded this we'll see the works and now after the war document is open now we'll start referring to this ranges how we set it.

    Up so first let's set up the date range so this range equal to again like we have done it earlier this document dot sorry doc Schurman bookmarks and then it's.

    Gonna be the first one is gonna be this contract date the country date are gonna ride it to see date so this is were we're gonna ride the seeding maybe if you want we can also set up here the the.

    Range it should write - okay for example let's say we have to write it to see babe we can also specify here and dynamically construct code but for now for to make it simple let me put it.

    Here so this is gonna be this range okay and then we can say this range dot text is equal to this value okay Contracting so we can see a range and then we want to format this so for.

    Example if I print this out gonna give me this date now let's format this to the format everyone let's format and we want this to be in month comma date and then here.

    Okay in this format like that okay maybe four months stay like this so this is what we want to write to the word in this particular cell okay I'm gonna close this let's try.

    To run this again okay XO it seems to not like this format somehow Oh God do this okay so we'll update this with the variable now I'm going to f5 document is.

    Open if I do f8 you see the values written here it's automatically underlining it you can also specify that from here as well.

    For example you can see this dot 4 dot bold you can see it false or true for example make it true this range underline you can also underline in these different ways for example the one.

    That we have now is this I think underline tick underline single or maybe like this ok so now that this is working we'll replicate this block ok again we can you know I looked through the range.

    And do this automatically by passing this as as a function but for now we're just gonna do it in this way now I'm going to close this don't save it so first is the date we've done for.

    Didn't always go to the tenant and next is going to be the landlord it's gonna be a team if I'm not mistaken with nameless tenant okay so tenant we want to write the.

    Tenant and then next is download the download and address one okay let's put that in the parking was this and here this value will be written here now we don't need the format it like this.

    He'll quickly summarize this now so we're saying you know like the bookmark tenant where we created in which we created in the word document in that particular bookmark we want to put the.

    Tenon this particular value from Excel into this particular tenant X and it will be picked up from here okay so this thing you know make it bold make it underline like that similarly for the.

    Landlord so this is the word bookmark and then we're putting a value for Mac so this is the axial madness okay so now let's try to run it one more time we'll have to Louie in like clearing of.

    This memory okay so you can see you know like this prefilled underlying bold and then the tender name okay so now if you go here to output.

    DISCLAIMER: In this description contains affiliate links, which means that if you click on one of the product links, I'll receive a small commission. This helps support the channel and allows us to continuetomake videos like this. All Content Responsibility lies with the Channel Producer. For Download, see The Author's channel. The content of this Post was transcribed from the Channel: https://www.youtube.com/watch?v=RQgOxv6nrE0
Previous Post Next Post