Can you please help me for Excel to Word Macro

Status
Not open for further replies.

fabcat1

New Member
Joined
May 20, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi,

I've just started to develop a VBA macro (no experience in development at all) o_O

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 ?
 

Attachments

  • moulinette.png
    moulinette.png
    94.6 KB · Views: 10

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
let me rephrase what you are trying to achieve:
You have created some code to process the first line of your data (apart from saving the document with the name in B2&C2)

What yo want to do is create a document for each line in the worksheet and process it like in your code.

Is that correct?
 
Upvote 0
Hi Sijpie,

Thanks for considering my thread
Since this message I've received support from another member in another thread.

The macro is creating a word document (open a template and once filled save it with the correct name) for each line and fill the bookmarks with the data in the different cells of the line


This thread can be closed
I don't know how to
If someone knows please tell me

Thanks
 
Upvote 0
This thread can be closed
I don't know how to
If someone knows please tell me
Threads are not closed on the board. However, if you received an answer that solves your problem, then you can mark that post as the solution to help future readers. Or, if you solved your own question, or if you find another thread that solves it, then you can post your own solution or the link to the solution thread and mark your post as the solution.
Otherwise, please do not mark a post as the solution that doesn't contain an answer.
 
Upvote 0
Can you post the link to the other thread ?
 
Upvote 0
Duplicate to: Loop problem

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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