OldRod
01-09-2007, 07:52 AM
We have run into a problem. We use Visual Foxpro to control Microsoft Word and use it to build a new Word document from pieces of a master Word document.
The master document is divided up with bookmarks and Foxpro steps through a list of items to see which the user has selected and based on that list it then selects the corresponding bookmarked text from the master file, copies it and pastes it into the new document.
Each pasted item is in it's own section so footers/headers can be unique and once we are all done, we print the new document.
This worked fine in Office 2000 and we've used it hundreds of times, but we recently upgraded to Office 2003 and now our paste is acting differently.
Here is the relevant code:
oWdSourceDoc.activate
*** Copy Body ********************
oWdSourceDoc.Bookmarks(mWdBookMark).select
oWord.Selection.Copy
oWdDestDoc.activate
RangeStart = oWdDestDoc.Content.End -1
RangeEnd = oWdDestDoc.Content.End -1
oWord.ActiveDocument.Range(RangeStart,RangeEnd).Select
oWord.Selection.Paste
WITH oWord.Selection
.WholeStory
.Font.Name = "Arial"
.Font.Size = 8
ENDWITH
*** Enter Header Text ********************
IF oWord.ActiveWindow.ActivePane.View.Type = 1 OR oWord.ActiveWindow.ActivePane.View.Type = 2
oWord.ActiveWindow.ActivePane.View.Type = 3
ENDIF
HeaderText = ALLTRIM(ThisForm.Client_Name) + CHR(10) + ALLTRIM(wpname) + CHR(10) _
+ yeDay + ALLTRIM(ThisForm.prog_year)
IF oWord.ActiveWindow.ActivePane.View.Type = 1 OR _
oWord.ActiveWindow.ActivePane.View.Type = 2
oWord.ActiveWindow.ActivePane.View.Type = 3
ENDIF
oWord.ActiveWindow.ActivePane.View.SeekView = 9
WITH oWord.Selection
.WholeStory
.delete
.Font.Name = "Arial"
.Font.Size = 8
.ParagraphFormat.Alignment = 1
.TypeText(HeaderText)
ENDWITH
oWord.ActiveWindow.ActivePane.View.SeekView = 0
*** Enter Footer Text ********************
oWord.ActiveWindow.ActivePane.View.SeekView = 10
WITH oWord.Selection
.wholestory
.delete
.Font.Name = "Arial"
.Font.Size = 8
.ParagraphFormat.Alignment = 2
.TypeText(ALLTRIM(wpnum))
ENDWITH
oWord.ActiveWindow.ActivePane.View.SeekView = 0
*** Create next section *****************
IF NumCreated < NumSelected
oWord.Selection.InsertBreak(2)
NumCreated = NumCreated + 1
oWord.ActiveWindow.ActivePane.View.SeekView = 9
oWord.Selection.HeaderFooter.LinkToPrevious = .F.
oWord.ActiveWindow.ActivePane.View.SeekView = 0
oWord.ActiveWindow.ActivePane.View.SeekView = 10
oWord.Selection.HeaderFooter.LinkToPrevious = .F.
oWord.ActiveWindow.ActivePane.View.SeekView = 0
ENDIF
What's happening now is that all of the pasted text is ending up in the very last section, rather than in each section as the document is built. I'm sure it has something to do with our range we are selecting when doing the paste, or when inserting the next section, but we just can't see the problem - and the fact that it worked in Word 2000, but not 2003 is puzzling.
Can anyone see what we are doing wrong here? Thanks!
*edited to break long lines
The master document is divided up with bookmarks and Foxpro steps through a list of items to see which the user has selected and based on that list it then selects the corresponding bookmarked text from the master file, copies it and pastes it into the new document.
Each pasted item is in it's own section so footers/headers can be unique and once we are all done, we print the new document.
This worked fine in Office 2000 and we've used it hundreds of times, but we recently upgraded to Office 2003 and now our paste is acting differently.
Here is the relevant code:
oWdSourceDoc.activate
*** Copy Body ********************
oWdSourceDoc.Bookmarks(mWdBookMark).select
oWord.Selection.Copy
oWdDestDoc.activate
RangeStart = oWdDestDoc.Content.End -1
RangeEnd = oWdDestDoc.Content.End -1
oWord.ActiveDocument.Range(RangeStart,RangeEnd).Select
oWord.Selection.Paste
WITH oWord.Selection
.WholeStory
.Font.Name = "Arial"
.Font.Size = 8
ENDWITH
*** Enter Header Text ********************
IF oWord.ActiveWindow.ActivePane.View.Type = 1 OR oWord.ActiveWindow.ActivePane.View.Type = 2
oWord.ActiveWindow.ActivePane.View.Type = 3
ENDIF
HeaderText = ALLTRIM(ThisForm.Client_Name) + CHR(10) + ALLTRIM(wpname) + CHR(10) _
+ yeDay + ALLTRIM(ThisForm.prog_year)
IF oWord.ActiveWindow.ActivePane.View.Type = 1 OR _
oWord.ActiveWindow.ActivePane.View.Type = 2
oWord.ActiveWindow.ActivePane.View.Type = 3
ENDIF
oWord.ActiveWindow.ActivePane.View.SeekView = 9
WITH oWord.Selection
.WholeStory
.delete
.Font.Name = "Arial"
.Font.Size = 8
.ParagraphFormat.Alignment = 1
.TypeText(HeaderText)
ENDWITH
oWord.ActiveWindow.ActivePane.View.SeekView = 0
*** Enter Footer Text ********************
oWord.ActiveWindow.ActivePane.View.SeekView = 10
WITH oWord.Selection
.wholestory
.delete
.Font.Name = "Arial"
.Font.Size = 8
.ParagraphFormat.Alignment = 2
.TypeText(ALLTRIM(wpnum))
ENDWITH
oWord.ActiveWindow.ActivePane.View.SeekView = 0
*** Create next section *****************
IF NumCreated < NumSelected
oWord.Selection.InsertBreak(2)
NumCreated = NumCreated + 1
oWord.ActiveWindow.ActivePane.View.SeekView = 9
oWord.Selection.HeaderFooter.LinkToPrevious = .F.
oWord.ActiveWindow.ActivePane.View.SeekView = 0
oWord.ActiveWindow.ActivePane.View.SeekView = 10
oWord.Selection.HeaderFooter.LinkToPrevious = .F.
oWord.ActiveWindow.ActivePane.View.SeekView = 0
ENDIF
What's happening now is that all of the pasted text is ending up in the very last section, rather than in each section as the document is built. I'm sure it has something to do with our range we are selecting when doing the paste, or when inserting the next section, but we just can't see the problem - and the fact that it worked in Word 2000, but not 2003 is puzzling.
Can anyone see what we are doing wrong here? Thanks!
*edited to break long lines