Macro sending data between Excel and Word

Dani2735

New Member
Joined
Dec 25, 2018
Messages
1
Hello, I'm working on a project which consists on two documents, an Excel and a Word files.

Excel contains some data in some cells, while Word contains some DocProperty fields.

I want to take the data in the Excel cells and insert it into the Word fields so every time I change the data in the cells it got updated in the fields.

I've developed a macro in Excel that does this, but the problem is that it creates a new document every time I execute it.

Is it possible to modify it so it changes Word fields without creating new copies of the document?

Here it's the code:

Code:
Sub Update_fields()

patharch = ThisWorkbook.Path & "\NewDoc.docx"
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.documents.Add Template:=patharch, NewTemplate:=False, DocumentType:=0


CMC = objWord.ActiveDocument.CustomDocumentProperties("cell1")
Ref_cell1 = Hoja1.Cells(1, 4)


CMS = objWord.ActiveDocument.CustomDocumentProperties("cell2")
Ref_cell2 = Hoja1.Cells(2, 4)


DEL = objWord.ActiveDocument.CustomDocumentProperties("cell3")
Ref_cell3 = Hoja1.Cells(3, 4)


objWord.Selection.Move 6, -1
objWord.ActiveDocument.CustomDocumentProperties("cell1") = Ref_cell1
objWord.ActiveDocument.CustomDocumentProperties("cell2") = Ref_cell2
objWord.ActiveDocument.CustomDocumentProperties("cell3") = Ref_cell3


objWord.Activate


End Sub

Thank you so much.

Best regards.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
All you need for this is to link the two files. To do that, simply copy the Excel data, then paste it into Word using Paste Special with the 'paste link' option and your preferred data format. No code required.
 
Upvote 0

Forum statistics

Threads
1,223,721
Messages
6,174,096
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top