![]() |
excel / word problem
Hi This is half excel related as I am using code to transfer rows of
info to a word doc from excel in a mail merge fashion. I cant use object lib references so i have to have the bookmarks in word pre written. I have a word document and I need to create a number of bookmarks in a pattern throughout the workbook. There are 5 bookmarks in the same position on each page and I need to duplicate this throughout the document. Same page layout, same bookmark placement but bookmark name incremented by one each time. I can obviously manage a copy and paste to get the desired amount of pages but I dont know how to add the bookmarks. I have posted an attachment with the word doc template in a zip. This has 3 records / pages within at the moment and the bookmarks are named in page 1 like this - AIName1 AIRef1 Operator1 Manager1 Address1 MeterNo1 so the rest of the bookmarks ideally would be the same but with the page number instead of the 1. I hope i have posted it clear enough. I know in the past I find it difficult to explain myself. Rob *** Sent via Developersdex http://www.developersdex.com *** |
excel / word problem
Hi Rob,
This is Word VBA. Try posting in a Word VBA forum. Once you have mastered the code you can copy and paste it into Excel and running from there - but the code and syntax remains Word specific. With respect to the Excel part of your post, why can't you use object lib references? And if you choose not to, why do you have to have the bookmarks prewritten in Word? This isn't the case if you use late binding. Below I've pasted some hastily scribbled code which creates a new Word doc and writes in the fields from each column on a separate page of a Word doc. You could also add Bookmarks (try recording a macro in Word) but I understood from your email that they were a means to an end for you - you didn't really need to use bookmarks. Sub CreateMailMergeyTypeThing() Dim oW As Object Dim oDoc As Object Dim lRow As Long, iCol As Integer Set oW = GetObject(, "Word.Application") 'create new document Set oDoc = oW.Documents.Add 'Assuming you have worksheet with 5 fields in columns With ActiveSheet lRow = 2 Do While .Cells(lRow, 1) < "" For iCol = 1 To 5 oW.Selection.TypeText Text:=.Cells(lRow, iCol).Value oW.Selection.TypeParagraph Next iCol oW.Selection.InsertBreak Type:=7 'wdPageBreak lRow = lRow + 1 Loop End With Set oW = Nothing Set oDoc = Nothing End Sub Cheers, Gareth PS - People really frown upon the posting on attachments on this NG. Rob Hardgreaves wrote: Hi This is half excel related as I am using code to transfer rows of info to a word doc from excel in a mail merge fashion. I cant use object lib references so i have to have the bookmarks in word pre written. I have a word document and I need to create a number of bookmarks in a pattern throughout the workbook. There are 5 bookmarks in the same position on each page and I need to duplicate this throughout the document. Same page layout, same bookmark placement but bookmark name incremented by one each time. I can obviously manage a copy and paste to get the desired amount of pages but I dont know how to add the bookmarks. I have posted an attachment with the word doc template in a zip. This has 3 records / pages within at the moment and the bookmarks are named in page 1 like this - AIName1 AIRef1 Operator1 Manager1 Address1 MeterNo1 so the rest of the bookmarks ideally would be the same but with the page number instead of the 1. I hope i have posted it clear enough. I know in the past I find it difficult to explain myself. Rob *** Sent via Developersdex http://www.developersdex.com *** |
All times are GMT +1. The time now is 12:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com