Multiply Word Document--HELP

T

Thejan Mendis

Hi,

Is there way I could access anther word document when main word document run
with a word macro.



THEJAN
 
M

mksmith

Yes, you have to use pointers.

In the code which you have you create a pointer which points to the first
document, the ActiveDocument.

Then you open up the second document and then SET a pointer to that one
and then all you do is to reference each document in turn by the object
pointers, as in this example below.

This example counts sum of the bookmarks in the active document and also
in another document which it will open itself.

It's not a perfect example, but it may give you an idea what is going on.
Again, may I refer you to my web site?


Sub CountBookmarks

Dim oDocument1 as Document
Dim oDocument2 as Document

dim nBookmarks1 as Long
dim nBookmarks2 as Long

Set oDocument1 = ActiveDocument
Set oDocument2 = Documents.Open ("...")

nBookmarks1 = oDocument1.Bookmarks.Count
nBookmarks2 = oDocument2.Bookmarks.Count

oDocument2.Close wdDoNoSaveChanges

MsgBox "These documents have a total of " & str$(nBookmarks1 +
nBookmarks2) & " bookmarks.", vbOKOnly, "Bookmark Counter"

End Sub


Regards
Malc
www.dragondrop.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top