Lunar Beam


Hi,

I have two documents which have roughly similar tables that need to be filled in Microsoft Word.

I would like to have a macro that updates a cell in a 5-by-5 table in B.doc when a cell in a 5-by-5 table in A.doc is updated.

1) A.doc is updated.

2) B.doc is opened, then updated.

3) Both documents save themselves.

It would be best if steps 1-3 are completed with a click of the button.

Thank you!





Re: Need to link two word documents together.

Adamus Turner


I have found success in VBA macros by recording a macro, completing the desired steps, stop the recording, and viewing the code generated by the macro recorder. (Alt+F11) This will give you the base for code. You can make modifications as needed.

Without writing the code for you, I would approach this as follows:

1. Record a macro

2. Update cell in A.doc table

3. Open B.doc

4. Update B.doc

5. Save both documents.

6. View code (Alt+F11)

Once you have written some code, if you still have questions, please post the code and we'll roll with that.

Adamus







Re: Need to link two word documents together.

Lunar Beam

Hi Adamus,

Somehow while recording my macro I am unable to click and type directly into the cell of the table. Hence all the selection.typebackspace.

'AllenHI Macro
' Macro recorded 6/12/2007 by yy'


Selection.MoveRight Unit:=wdCharacter, Count:=30
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeText Text:="HIHIHI"
ChangeFileOpenDirectory "C:\Documents and Settings\yy\Desktop\yy\"
Documents.Open FileName:="""Fortune.doc""", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=26
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeText Text:="HIHIHI"







Re: Need to link two word documents together.

Shasur

You can used Open method to open the document and do the necessary

Code Snippet

Sub Update_Documents()

Dim ADoc As Word.Document
Dim BDoc As Word.Document

Set ADoc = Documents.Open("C:DocumentA.DOC")

' Update Your Stuff

Set BDoc = Documents.Open("C:DocumentB.DOC")

ADoc.Save
ADoc.Close

BDoc.Save
BDoc.Close
End Sub

Cheers

Shasur