FoxPro/foxpro
Expert: Carla Fair-Wright - 1/8/2007
Question
-------------------------------------------
The text above is a follow-up to ...
-----Question-----
-------------------------------------------
The text above is a follow-up to ...
-----Question-----
-------------------------------------------
The text above is a follow-up to ...
-----Question-----
I have a 43 .doc files. i would like to combine all files in one.doc file? can i use fox pro OLE to accomplish above
-----Answer-----
Ashisha,
I don't know what version of FoxPro you are using or what version of Word. You can use Foxpro to manipulate word documents. You'll have to use VBA which means FoxPro 3.0 or higher.
Dale F. Wiley has a great how-to on this
http://experts.about.com/q/Microsoft-Word-1058/combining-word-documents.htm
To use VBA start the Macro recorder.
Open the first document
Go to Insert, File
Navigate and select the file you want to combine and then click on Insert or Open.
Insert Files Number Two
Stop it when done.
View the macro and copy it to VFP.
This article will help you with the VBA conversion to VFP format
How to print a general field by using Word and Visual FoxPro 9.0
support.microsoft.com/kb/175173
Also this article might give you some ideas.
Creating a Table of Contents Spanning Multiple Documents
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=148
Post in the forum if you have any problems.
Carla
Thanks Carla for quick response, I am using vfp 6.0
PARA lext, lbrow, lrpt
lTrans=.f.
nErrorCount=2
close table all
use macrotxt in 0 excl
sele macrotxt
zap
appe blank
repl l1 with "Sub CreateManual()"
use macroins in 0 excl
use macfiles in 0 excl
sele macfiles
zap
=messagebox("Select the Client-Specific Manual Pages List - TXT File",0+64,"Select TXT File")
appe from ? type sdf
store reccount() to nMaxRec
go top
do while ! eof()
store recno() to nRecNo
store '"'+allt(filename)+'", _' to cFileName
sele macroins
store allt(f1)+cFileName to cL1
sele macrotxt
appe blank
repl l1 with cL1
nCount=2
sele macroins
do while nCount<=12
store "f"+allt(str(nCount)) to cFldName
store &cFldName to cL1
sele macrotxt
if nRecNo=nMaxRec and nCount=10
* do nothing
else
appe blank
repl l1 with cL1
endif
nCount=nCount+1
sele macroins
enddo
sele macfiles
skip
enddo
sele macrotxt
appe blank
repl l1 with "End Sub"
copy to macrotxt.doc type sdf
! /N "C:\Program Files\Microsoft Office\Office11\WINWORD.EXE" K:\ChoiceOneLink\Manual\GroupGuideTemplate\macrotxt.doc
retu
above is my code.after this i go to word and create the macro word by coping the text. and i manually run the macro in in word and save the file with new name.
What i am donid in word i would like to do in vfp 6.0 using OlE. cloud you please help me ?
Thanks
Ashisha
-----Answer-----
Ashisha,
I believe this will work for you.
#DEFINE wdStory 6
#DEFINE No_ConfirmConversions .F.
#DEFINE No_Link .F.
#DEFINE No_Attachment .F.
loWordSession = CREATEOBJECT('Word.Application')
loWordSession.Documents.Add
loWordSession.Visible = .T. && for testing
MESSAGEBOX("Select the Client-Specific Manual Pages List - TXT File",0+64,"Select TXT File")
lcFileName = GETFILE("txt")
* we ask for the 43 files to be added. I suggest you change this to a listbox
* using a listbox will allow to user select all the files at one time or
FOR liNumberOfDocuments = 1 TO 43
WITH loWordSession
.SELECTION.EndKey( wdStory ) && go to the end of the document
.SELECTION.InsertFile(lcFileName,"", No_ConfirmConversions,No_Link,No_Attachment)
MESSAGEBOX("Select the Client-Specific Manual Pages List - TXT File",0+64,"Select TXT File")
lcFileName = GETFILE("txt")
* no file was selected
IF EMPTY( lcFileName )
EXIT
ENDIF
ENDWITH
ENDFOR
* this is the combined document we save
lcFileName = "macrotxt.doc"
loWordSession.Visible = .T.
WITH loWordSession
.ChangeFileOpenDirectory ( "K:\ChoiceOneLink\Manual\GroupGuideTemplate\" )
.ActiveDocument.SAVEAS( lcFileName )
.ActiveDocument.CLOSE()
ENDWITH
* we close word application
loWordSession.Quit
RETURN .T.
Good Luck,
Carla
Hi Carla
Above works perfecty
I have formatted document templet on which all the documents are copied
and paste. I would like to insert filename and path in footerfor each
documents through OLE
-----Answer-----
Ashisha,
Try this:
#DEFINE wdHeaderFooterPrimary 1
WITH loWordSession.ActiveDocument.Sections(1)
.Footers(wdHeaderFooterPrimary).Range.Text = "<Replace this with your text>"
EndWith
Carla
Hi Carla,
That works but i already had a footer in my templet. When I use above code it removes the previos footer and repaces wit filename
Also i would like to formate the font size with 8 for the file name
Could you please help me with it?
Thanks so much for your help
Ashisha
AnswerAshisha,
* we save the text in the footer and add to it
WITH loWordSession.ActiveDocument.Sections(1)
lcText = .Footers(wdHeaderFooterPrimary).Range.Text
lcText = lcText + "<Replace this with your text>"
.Footers(wdHeaderFooterPrimary).Range.Text = lcText
EndWith
The footer font can be change with the font attribute. The syntax is in your VBA online.
Cheers,
Carla