Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Microsoft Word

Status
Not open for further replies.

Kennt

Programmer
Jun 2, 2002
1
US
I am working with Microsoft Word (Word) 97. I would like to be able to use Visual Basic for Applications to write Macros in VBA to operate on my subject Word Document. Do I understand, correctly that for every key stroke in Word, there is a corresponding "action" (for the lack of a better phrase) in VBA? Where and how can I find a list of these correspondences? FOr example, if I want to press the ENTER key in my macro, how can that be done? Or, how can margins be set within a macro? Fonts changed and size changed?? I assume that Version 5 of VBA is included in Word 97; if that is incorrect, I may have a problem. I would appreciate hearing from anyone with possible knowledge of how to answer any of these questions.

Thanks, Kennt
 
Tell us what you want this macro to do and then we'll be better placed to help you.
 
Older macro languages like the original DOS based Lotus 123 spreadsheet were largely a record of key strokes. That does not work in a windows environment largely because the mouse is so flexible, menus can be customised by users and so on.

Modern programs are constructed using objects. Examples are Excel workbooks, worksheets, ranges,..
Word tables, paragraphs, headers..

What you do is write code that manipulates those objects. In Excel you could have
Code:
Activecell.value = 12345 
ActiveSheet.Name = "Ken"

This takes the active cell object and sets its value property to 12345. Then the current worksheet name which appears on the tab is changed to Ken.

If you want to write macros for Word you need to have some understanding of the Word objects and how you can do things with them. The best way is to start with some simple task and find out how it is done. For example, in Word how would the order of two words be swapped.

You will find it difficult to begin but there are a lot of people who can help when you get stuck.

The great advantage of this way of doing things is we have the same language for all MS Office products - you just have different objects to play with.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top