R
ryguy7272
I am almost done (I think) with a project for my supervisor. I am now trying
to get values, that show in a ListBox, to enter into a Word document. The
document has many MergeField elements in it, some of which include
First_Name, Last_Name, Address, City, Zip, Number (which is a unique ID
number.) These are located throughout the document and I think MergeFields
are the best choice for formatting purposes (as far as I know Bookmarks don’t
give users much control over formatting). The data comes from an Excel
sheet, which has several named ranges to identify data in each column. Doug
gave me code to get most of this running (thanks a lot). Now, I am just
trying to get the data, that is displayed in the ListBox, into the
appropriate MergeFields in the document. Does anyone here have any idea how
to do this? I’ve seen a few examples online, but not many, and the ones that
I did see don’t seem to be helpful at all.
As an aside, Doug game me some code before, which was great for another
project where I used a Bookmark to reserve a location for a reference that I
used for another project. The code is:
Private Sub CommandButton1_Click()
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Addressee = Addressee & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Addressee").Range.InsertAfter Addressee
UserForm1.Hide
End Sub
This is pretty much what I want to do with my MergeFields. The code that I
need may be very similar to this, but I’m not sure because I’ve never used
MergeFields before. I tried the Macro Recorder; it didn’t help much. Any
guidance would be greatly appreciated.
Regards,
Ryan---
to get values, that show in a ListBox, to enter into a Word document. The
document has many MergeField elements in it, some of which include
First_Name, Last_Name, Address, City, Zip, Number (which is a unique ID
number.) These are located throughout the document and I think MergeFields
are the best choice for formatting purposes (as far as I know Bookmarks don’t
give users much control over formatting). The data comes from an Excel
sheet, which has several named ranges to identify data in each column. Doug
gave me code to get most of this running (thanks a lot). Now, I am just
trying to get the data, that is displayed in the ListBox, into the
appropriate MergeFields in the document. Does anyone here have any idea how
to do this? I’ve seen a few examples online, but not many, and the ones that
I did see don’t seem to be helpful at all.
As an aside, Doug game me some code before, which was great for another
project where I used a Bookmark to reserve a location for a reference that I
used for another project. The code is:
Private Sub CommandButton1_Click()
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Addressee = Addressee & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Addressee").Range.InsertAfter Addressee
UserForm1.Hide
End Sub
This is pretty much what I want to do with my MergeFields. The code that I
need may be very similar to this, but I’m not sure because I’ve never used
MergeFields before. I tried the Macro Recorder; it didn’t help much. Any
guidance would be greatly appreciated.
Regards,
Ryan---