Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Macro to fill out MS word fields from excel fields (2003 version)

1) Copy Field A1, and B1 from current excel sheet called "Summary"
2) Open a specific template MS word or a document located on a specific computer location
3) Paste info from Step 1 into specific sections of the Word document.

Extremely valuable.
Thank you,
JP
0
easycapital
Asked:
easycapital
  • 4
  • 3
1 Solution
 
AndrewK80Commented:
You can do this using the mail merge function.
0
 
Arno KosterCommented:

As AndrewK80 indicated, this is best performed using standard mail merge function.
When you want to perform it by code, it comes down to something like

Word.ActiveDocument.Content.Text = Replace(Word.ActiveDocument.Content.Text, "[word field]", "[excel field]")
0
 
easycapitalAuthor Commented:
I am addressing the initial question by attaching an excel example with values in A1 and B1. Then I indicate in the word document where A1 and B1 should go by typing AAA and XXX respectively.

Assuming both documents are saved in the desktop, could you provide the solution including the macro the runs it?

Thanks,
JP excel-mail-merge-example.xls word-mail-merge.doc
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Arno KosterCommented:
sure, give me a moment...
0
 
Arno KosterCommented:
Paste this macro in the sheet1 part in the Excel VBA editor
Update the actual path to the desktop location of the files

Sub perform_mail_merge()

    '-- open word application
    Set word = CreateObject("Word.Application")
    word.Visible = True
    
    '-- open document
    word.documents.Open "C:\[path to desktop]\word-mail-merge.doc"
    Set doc = word.activedocument
    
    '-- process fields
    doc.Content.Text = Replace(doc.Content.Text, "AAA", Range("A1"))
    doc.Content.Text = Replace(doc.Content.Text, "XXX", Range("B1"))
    
    '-- save document
    doc.SaveAs "C:\[path to desktop]\merged_document.doc"
    
    '-- close word application
    doc.Close
    word.Quit
    Set doc = Nothing
    Set word = Nothing

End Sub

Open in new window

0
 
easycapitalAuthor Commented:
I need a bit more time.
0
 
Arno KosterCommented:
Teylyn,

the solution posed in comment

35139604

is, in my opinion, a correct answer to the question of the author.
0
 
easycapitalAuthor Commented:
Thank you.

Sorry for the delay.  I have been swamped.

JP
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now