1st macro:
Sub ReplaceText()
Dim WordApp As Object
Dim wdoc As Object
Set wAPP = CreateObject("Word.Application")
wAPP.DisplayAlerts = False
wAPP.Visible = True
Set wdoc = wAPP.Documents.Add(Template:="C:\Users\Desktop\Site Survey VBA TEST 001.docx", NewTemplate:=False, DocumentType:=0)
With wdoc
.Application.Selection.Find.Text = "<<Customer>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C2")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Customer Site>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C3")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Customer Site Code>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C4")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Customer Site Address>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C5")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Site Contact>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C7")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Telephone Number>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C8")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Email Address>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C9")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF12>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D12")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF13>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D13")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF14>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D14")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF15>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D15")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF16>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D16")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF17>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D17")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF18>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D18")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF19>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D19")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF20>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D20")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF21>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D21")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF22>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D22")
.Application.Selection.EndOf
.SaveAs2 Filename:=("C:\Users\ANash\Desktop\Site Survey CUSTOMER VERSION.dox"), _
FileFormat:=wdFormat.doc, AddtoRecentFiles:=False
End With
End Sub
(This macro works fine and opens up the doc template and populates the document.. the problem im having is when i use the third macro which is a button to run both macros, it opens up multiple replications of the template and does not populate the data from Macro one or Macro 2.
Macro 2:
Sub ReplaceText()
Dim WordApp As Object
Dim wdoc As Object
Set wAPP = CreateObject("Word.Application")
wAPP.DisplayAlerts = False
wAPP.Visible = True
With wdoc
.Application.Selection.Find.Text = "<<RO12>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("B12")
.Application.Selection.EndOf
End With
End Sub
( I really just need to know what commands I need to utilise to run the macros at the same time when Macro 3 button is pressed, to generate on the same word document which opens when Macro 1 is ran, and for macro 2 to run on the same word document and populate the information from sheet2 in excel any help any one can give would be greatly appreciated)
For info Macro 3:
Sub Button1_Click()
Call Module1.ReplaceText 'Macro1
Call Module2.ReplaceText 'Macro2
Call Button1_Click 'Macro3
End Sub
If I can manage to get this to work.. I will be adding additional macros to further sheets within the same workbook in the hopes that i can generate all information onto the single word.doc template
Sub ReplaceText()
Dim WordApp As Object
Dim wdoc As Object
Set wAPP = CreateObject("Word.Application")
wAPP.DisplayAlerts = False
wAPP.Visible = True
Set wdoc = wAPP.Documents.Add(Template:="C:\Users\Desktop\Site Survey VBA TEST 001.docx", NewTemplate:=False, DocumentType:=0)
With wdoc
.Application.Selection.Find.Text = "<<Customer>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C2")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Customer Site>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C3")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Customer Site Code>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C4")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Customer Site Address>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C5")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Site Contact>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C7")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Telephone Number>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C8")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<Email Address>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("C9")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF12>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D12")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF13>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D13")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF14>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D14")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF15>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D15")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF16>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D16")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF17>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D17")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF18>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D18")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF19>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D19")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF20>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D20")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF21>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D21")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<WF22>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("D22")
.Application.Selection.EndOf
.SaveAs2 Filename:=("C:\Users\ANash\Desktop\Site Survey CUSTOMER VERSION.dox"), _
FileFormat:=wdFormat.doc, AddtoRecentFiles:=False
End With
End Sub
(This macro works fine and opens up the doc template and populates the document.. the problem im having is when i use the third macro which is a button to run both macros, it opens up multiple replications of the template and does not populate the data from Macro one or Macro 2.
Macro 2:
Sub ReplaceText()
Dim WordApp As Object
Dim wdoc As Object
Set wAPP = CreateObject("Word.Application")
wAPP.DisplayAlerts = False
wAPP.Visible = True
With wdoc
.Application.Selection.Find.Text = "<<RO12>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("B12")
.Application.Selection.EndOf
End With
End Sub
( I really just need to know what commands I need to utilise to run the macros at the same time when Macro 3 button is pressed, to generate on the same word document which opens when Macro 1 is ran, and for macro 2 to run on the same word document and populate the information from sheet2 in excel any help any one can give would be greatly appreciated)
For info Macro 3:
Sub Button1_Click()
Call Module1.ReplaceText 'Macro1
Call Module2.ReplaceText 'Macro2
Call Button1_Click 'Macro3
End Sub
If I can manage to get this to work.. I will be adding additional macros to further sheets within the same workbook in the hopes that i can generate all information onto the single word.doc template