I have the below code to create a quote letter in Word from an Excel workbook and it works great, however, I also want the same macro to insert a table from my Excel workbook to the same Word document. Is this possible?
I've had a look through the forums and I was able to find various examples of inserting tables to new word documents, but I wasn't sure how to combine that with the code I already have.
Thanks in advance!
</contact_email></contact_person></billing_address_line2></billing_address_line1></client_name></quote_number>
I've had a look through the forums and I was able to find various examples of inserting tables to new word documents, but I wasn't sure how to combine that with the code I already have.
Thanks in advance!
Code:
Sub CreateQuoteLetter()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.add(Template:="I:\Mark B\New Job Template Resources\Custom Office Templates\Certifed Quote Template.dotm", NewTemplate:=False, DocumentType:=0)
With wDoc
.Application.Selection.Find.Text = "<quote_number>"
.Application.Selection.Find.Execute
.Application.Selection = Worksheets("Job Information").Range("K4")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<client_name>"
.Application.Selection.Find.Execute
.Application.Selection = Worksheets("Job Information").Range("C3")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<billing_address_line1>"
.Application.Selection.Find.Execute
.Application.Selection = Worksheets("Job Information").Range("C5")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<billing_address_line2>"
.Application.Selection.Find.Execute
.Application.Selection = Worksheets("Job Information").Range("C6")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<contact_person>"
.Application.Selection.Find.Execute
.Application.Selection = Worksheets("Job Information").Range("C4")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<contact_email>"
.Application.Selection.Find.Execute
.Application.Selection = Worksheets("Job Information").Range("C11")
.Application.Selection.EndOf
.SaveAs2 Filename:=thisWb.Path & ("\1. Quotation\") & Worksheets("Job Information").Range("K4") & (".docm"), _
FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
End With
End Sub