VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Using VB code to access MS Word Functions

Matmonk  (2 Submissions)   OLE/COM/DCOM/Active-X   Visual Basic 3.0   Advanced   Wed 3rd February 2021

This code is an example of how to use various functions contained within the Word Application object. To use this code you must first set a reference to the word libary then declare a word application object. This code shows how to use the search/replace functions, how to bold items, how to do a "Save As" from the code and how to insert lines. There are also a few miscellanous methods such as how to tell if a file exists and how to kill it. This piece of code was origonally written as part of a class module and was incorporated into a dll to be used by other application developers that I was working with. I have a few other examples from the class if anyone is interested, please drop me a line. I hope that this saves someone some time in using word. I have not found too many good books or code examples that explain how to use word as an object.

Inputs
the code is looking for a document that was pre-setup as a template. the fields that look like "<>" are place holders in the template. The replacement values were generated by stored procedures run against a sql server database. If there is interest I will post the ado routines that I used to get the data.

Assumes
make sure that you set a reference to the word object using the Project/References menu. Almost all variables (except those explicitly stated as local) are module level variables private to the class module. all the vbTab constants appended to the strings are used simple to align the text. If anyone knows of a better way to do this, I would love to hear it.

API Declarations
none -- this was part of a self contained class

Rate Using VB code to access MS Word Functions (4(4 Vote))
Using VB code to access MS Word Functions.bas

Using VB code to access MS Word Functions Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters