Dear all,
I developed a Word template with code.
The word template contains several Contentcontrols one of which holds each Cc the letter is to be sent to.
The letter content is all created programmatically from a SQL server database via Access.
Depending on the letter lenght one Ccs may end up occupying two pages. I used this code snipet to move the ContentControl down to the next page in such cases
'Get First CCs in one pageWordApp.Visible = True '(this is for testing purposes)
Set wrdCControl = wordDoc.SelectContentControlsByTag("txtCCs").Item(1)
intIndex = wordDoc.Range(0, wrdCControl.Range.start).Paragraphs.count
I = wordDoc.Paragraphs(intIndex).Range.Information(wdActiveEndAdjustedPageNumber)
J = wrdCControl.Range.Information(wdActiveEndAdjustedPageNumber)
If I < J Then
IntStartPatientAddress = intIndex - 1
Do Until I = J
intIndex = intIndex + 1
I = wordDoc.Paragraphs(intIndex).Range.Information(wdActiveEndAdjustedPageNumber)
Loop
For I = IntStartPatientAddress To intIndex - 1
wordDoc.Paragraphs(IntStartPatientAddress).Range.Paragraphs.Add
Next I
End If
I am new to Word VBA and there are likely more efficient ways to achieve this but for me it worked.
But when running the code on this user machine I noticed that the Range.Information(wdActiveEndAdjustedPageNumber) was giving different results to mine.
On the same document it was reporting that only two lines of the content form were on page two and the rest were on page 3. So it only moved the block down two paragraphs and the Cc ended up still occupying 2 pages.
On one occasion I happened to open the the document created from this user machine without running the code when the Word Document opens. One of the lines is showRevisions= false. So the document was opened showing the revisions and voila, the whole Cc was displaying on the third page.
I run once again the code line by line and stopped at the snipet mentioned above.
Then I decided to click on the inspect Document button in Word and after analysing the document it came up with a few suggestions one of which was "remove comments, revisions annotations..."
I did so and then continued running the code. This time it was matching what you could see on the screen and it moved the block perfectly to the third page.
But when I tried to create the document form scratch again now the code is throwing all kind of errors.
One of our IT guys tried the following without any success:
1. Reset Word and Access to default - did not work
2. Rename both Word and Access in XXXX’s profile - did not work
3. Repaired/reinstall Office - did not work
4. System restore to 4th December - did not work
5. Logged onto my computer as XXX - did not work
Any ideas?
Thank you very much for your help.