Hi,
I've just started to develop a VBA macro (no experience in development at all)
I've done so far the following code which successfully fil my Word template with the data of the first line of my excel file
I'd like now to do the following
when start the macro create a file with the content of the first line of the excel file, then name the file with the content of the column B and column C, save the file
create a new word file, fill the bookmarks with the content of the following line, name and save it
and so on
when the content of the first row of the excel file is empty, stop the macro
The code so far
Sub FillBookmarks()
Dim objWord As Object
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Data")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\Users\desktop\Template.docx"
With objWord.ActiveDocument
.Bookmarks("Site_Code").Range.Text = ws.Range("B2").Value
.Bookmarks("Site_Name").Range.Text = ws.Range("C2").Value
.Bookmarks("Demand_ref").Range.Text = ws.Range("D2").Value
.Bookmarks("Project_Title").Range.Text = ws.Range("E2").Value
.Bookmarks("Localisation").Range.Text = ws.Range("F2").Value
.Bookmarks("Requestor").Range.Text = ws.Range("G2").Value
.Bookmarks("Program_Manager").Range.Text = ws.Range("H2").Value
.Bookmarks("SAP_Code").Range.Text = ws.Range("I2").Value
.Bookmarks("Request_date").Range.Text = ws.Range("J2").Value
.Bookmarks("Target_date_Study").Range.Text = ws.Range("K2").Value
.Bookmarks("Target_date_Build").Range.Text = ws.Range("L2").Value
.Bookmarks("Project_Description").Range.Text = ws.Range("M2").Value
.Bookmarks("Objectives_and_deliverables").Range.Text = ws.Range("N2").Value
.Bookmarks("Out_of_scope").Range.Text = ws.Range("O2").Value
.Bookmarks("Assumptions").Range.Text = ws.Range("P2").Value
.Bookmarks("Budget_Material").Range.Text = ws.Range("Q2").Value
.Bookmarks("Budget_Partner").Range.Text = ws.Range("R2").Value
.Bookmarks("Budget_Internal_Ressources").Range.Text = ws.Range("S2").Value
.Bookmarks("Budget_Total").Range.Text = ws.Range("T2").Value
End With
Set objWord = Nothing
End Sub
Attached the excel file
Thanks a lot for your help ?
I've just started to develop a VBA macro (no experience in development at all)
I've done so far the following code which successfully fil my Word template with the data of the first line of my excel file
I'd like now to do the following
when start the macro create a file with the content of the first line of the excel file, then name the file with the content of the column B and column C, save the file
create a new word file, fill the bookmarks with the content of the following line, name and save it
and so on
when the content of the first row of the excel file is empty, stop the macro
The code so far
Sub FillBookmarks()
Dim objWord As Object
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Data")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\Users\desktop\Template.docx"
With objWord.ActiveDocument
.Bookmarks("Site_Code").Range.Text = ws.Range("B2").Value
.Bookmarks("Site_Name").Range.Text = ws.Range("C2").Value
.Bookmarks("Demand_ref").Range.Text = ws.Range("D2").Value
.Bookmarks("Project_Title").Range.Text = ws.Range("E2").Value
.Bookmarks("Localisation").Range.Text = ws.Range("F2").Value
.Bookmarks("Requestor").Range.Text = ws.Range("G2").Value
.Bookmarks("Program_Manager").Range.Text = ws.Range("H2").Value
.Bookmarks("SAP_Code").Range.Text = ws.Range("I2").Value
.Bookmarks("Request_date").Range.Text = ws.Range("J2").Value
.Bookmarks("Target_date_Study").Range.Text = ws.Range("K2").Value
.Bookmarks("Target_date_Build").Range.Text = ws.Range("L2").Value
.Bookmarks("Project_Description").Range.Text = ws.Range("M2").Value
.Bookmarks("Objectives_and_deliverables").Range.Text = ws.Range("N2").Value
.Bookmarks("Out_of_scope").Range.Text = ws.Range("O2").Value
.Bookmarks("Assumptions").Range.Text = ws.Range("P2").Value
.Bookmarks("Budget_Material").Range.Text = ws.Range("Q2").Value
.Bookmarks("Budget_Partner").Range.Text = ws.Range("R2").Value
.Bookmarks("Budget_Internal_Ressources").Range.Text = ws.Range("S2").Value
.Bookmarks("Budget_Total").Range.Text = ws.Range("T2").Value
End With
Set objWord = Nothing
End Sub
Attached the excel file
Thanks a lot for your help ?