Howdy,
So the main issue I have is after adding text/string info (pulled from excel; passed through a variable) to word, I attempt to add/insert a page break after all the text in the word document (end of page). However, doing so erases all the previously added text and simply leave the page break at the top of the first page. The code executes w/out error, so this leaves me with either a placement issue w/in the code or I don't fully grasp how VBA (from Excel) writes data to Word. Stepping through the code, I did notice the actual position cursor in Word remains at the very top of the page. Below is a generic ref. of what I'm attempting to code:
Define variables/objects
Create/open new Word document (not saved to anywhere)
1st Loop
Lookup/find selected text
IF Match text field to a database
2nd Loop
Grab pertinent info from database
Add info to Word (this data passed via a string variable)
Add new/next line to Word (via "InsertParagraphAfter" function)
End/Iterate 2nd Loop
Add page break to word (via [actual code sample] "wrddoc.Content.InsertBreak _ Type:=wdPageBreak"
End IF
End/ Iterate 1st Loop
Let me know if more info is needed. Just in case...the code is not currently tracking text/line/paragraph positions. I've searched this site and web on the above topic, but really only found topics on adding a page break without mentioning anything about positioning or why text might get deleted after inserting the break. I tried a section break as well...same issue.
Cheers,
Jonesy
So the main issue I have is after adding text/string info (pulled from excel; passed through a variable) to word, I attempt to add/insert a page break after all the text in the word document (end of page). However, doing so erases all the previously added text and simply leave the page break at the top of the first page. The code executes w/out error, so this leaves me with either a placement issue w/in the code or I don't fully grasp how VBA (from Excel) writes data to Word. Stepping through the code, I did notice the actual position cursor in Word remains at the very top of the page. Below is a generic ref. of what I'm attempting to code:
Define variables/objects
Create/open new Word document (not saved to anywhere)
1st Loop
Lookup/find selected text
IF Match text field to a database
2nd Loop
Grab pertinent info from database
Add info to Word (this data passed via a string variable)
Add new/next line to Word (via "InsertParagraphAfter" function)
End/Iterate 2nd Loop
Add page break to word (via [actual code sample] "wrddoc.Content.InsertBreak _ Type:=wdPageBreak"
End IF
End/ Iterate 1st Loop
Let me know if more info is needed. Just in case...the code is not currently tracking text/line/paragraph positions. I've searched this site and web on the above topic, but really only found topics on adding a page break without mentioning anything about positioning or why text might get deleted after inserting the break. I tried a section break as well...same issue.
Cheers,
Jonesy
Last edited: