Word Document Formating
Dear Expert
I create some table in word with following procedure.
These codes were written by Sir Cetin Basoz and by some other UT Professors.
The codes work fine.
#Define wdTableFormatColorful2 9
#Define wdTableFormatContemporary 35
#Define wdTableFormatElegant 36
#DEFINE wdAlignParagraphThaiJustify 9
#DEFINE wdOrientPortrait 0
#DEFINE wdOrientLandscape 1
#DEFINE wdCellAlignVerticalBottom = 3
*Local oWord As Word Application, lcTemp,lcHeader,ix
lcTemp = Forcepath(Sys(2015)+'.txt',Sys(2023))
Select code,desc,close_dr,close_cr ;
from master1 ;
into Cursor crsMyCursor nofilter
Copy To (m.lcTemp) Type Delimited With tab
lcHeader = ''
For ix = 1 To Fcount()
lcHeader = m.lcHeader + ;
Iif(Empty(m.lcHeader),'',Chr(9))+;
Field(m.ix)
Endfor
_Cliptext = m.lcHeader+Chr(13)+Chr(10)+Filetostr(m.lcTemp)
Erase (m.lcTemp)
oWord = Createobject('word.application')
oWord.DisplayAlerts = .f.
With oWord
.Documents.Add
With .ActiveDocument.Range
.Paste
With .ConvertToTable(Chr(9))
.AutoFormat(wdTableFormatColorful2)
Endwith
Endwith
.Visible = .T.
.Activate
.WindowState = 1
Endwith
Now I have some more questions in Word Table
1) How to add following paragraph at the top of the document
"Trial Balance" && It should be bold,underline and align center
2) How to add following second paragraph
"Duration from "
3) Space between paragraphs=Double
3) How to insert Custom Footer:
I want to insert Page X of Y at Bottom Right Footer.
Please Help
Hello Tariq.
It is very nice of Cetin and the others to write your code for you. However, this does not help you to learn anything so that you will be able to write your own code in the futute.
First of all, the easiest way to figure out how to write this code in VFP is to open Word and from the Tools menu select "Record Macro". Then, you do in Word interactively what you are trying to automate in VFP. After you arfe finished recording the macro, you can edit it and use this steps to converts the VBS code to VFP:
1. Add parentheses around the parameter list
2. Examine the calling prototype for the method in the object browser and rearrange the parameters in the generated macro so that they appear in the same order that they are listed here. Because VBA uses named parameters, their order does not matter. This is not so in VFP where parameters are positional. Regardless of the order of the parameters in the VBA macro, the Object Browser and IntelliSense always display them in the order required for correct Visual FoxPro syntax.
3. Remove the names of the parameters on the left side of the ‘:=’ as well as the ‘:=’
4. Replace the named constants with their values. This includes replacing True with 1 and False with 0. Note: An alternative would have been to add #DEFINE statements at the top of the method like this after looking up the values for the named constants in the Object Browser:
#DEFINE TRUE 1
#DEFINE FALSE 0
#DEFINE WDOPENFORMATAUTO 0
You can download the white paper and sample code from the conference session I gave on Automating Microsoft Office with VFP. The are several examples of automating Word and should give you plenty of information so that you can figure this out.