Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word Automation -- Page X of Y

Status
Not open for further replies.

CDavis

Programmer
May 5, 2000
155
US
I've been working on a project that includes automating MS Word for reports. I've purchased "Microsoft Office Automation with Visual FoxPro" from Hentzenwerke Publishing and it has been very helpful. However, I have been unable to determine how to Automate the Page X of Y feature that is available interactively in Word.

The following are VBA versions of what I'm trying to do:
Version 1:

Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
Selection.TypeText Text:=" of "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages

Version 2:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
ActiveWindow.ActivePane.VerticalPercentScrolled = 50
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=Selection. _
Range, RichText:=True
Selection.TypeParagraph
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages

Any help in converting to VFP will be appreciated.

CDavis
 
CDAvis

Unfortunatly as you may have discovered the "Type" property cannot be changed from VFP as it is read-only, may I suggest you write the procedure (Macro) in Word, save it, and play it from FoxPro.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

Thanks for the post. I suspected that I was spending far too much time to do something that should have been simple. I appreciate your suggestion about playing a macro. That should do it.

CDavis
 
For those of you who might have been interested in this thread, I saved a .dot template file with the Page X of Y function in the footer. The call then becomes:

oWord = CreateObject("Word.Application")
oDoc = oWord.Documents.Add("PageXofY.Dot")

You would need to include the path to the file if it is not in the default template location. Also you will need to distribute the template file with your application.

CDavis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top