Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I control table cell formatting via word automa
Message
 
 
To
11/06/2001 18:29:35
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00517862
Message ID:
00518194
Views:
18
David,

I sent this to you under separate cover, but I posted here too, in case someone else needs the answer.

Here's some code that should do what you want. Notice that I changed it to use WITH...ENDWITH constructs. Since it evaluates the object reference only once, it does run faster (though you'd have to go through lots of iterations to make it noticeable). However, it also has a better self-documenting capability...


#DEFINE wdCollapseStart 1
#DEFINE wdCollapseEnd 0
lnCustomerTbl = 1 && This is set as a #DEFINE in your code...change appropriately
lnCustCntr = 1 && This is set as a #DEFINE in your code...change appropriately

* Set a variable to the range that you want to use...in this case, a single cell
oRange = oDoc.tables(lncustomertbl).cell(lncustcntr,5).range

* Work with the Range object
WITH oRange
* Collapse the range to the start of the Range...this places
* the insertion point at the beginning of the cell (as opposed
* to at the EndOfRow marker)
.Collapse(wdCollapseStart) && must use the Collapse _method_

.Text = "currespmatr_customer.mrecommend"
* I don't have this table, so I'll add the reference as a text string

* Turn on Bold and Italic
.Bold = .T.
.Italic = .T.

* Heres where you had the error. Notice that you need to use the Range object's
* Collapse method...
*oDoc.tables(lncustomertbl).cell(lncustcntr,5).range(wdCollapseend)
&& got error 'does not support a collection'
.Collapse(wdCollapseEnd)

* Your Range is now the end of the text, so add the CR and the next text
* string (again, I'll place the reference as a char string)
.Text = CHR(13) + "alltrim(currespmatr_customer.mconcept)"

* Now set the attributes of the new text
.Bold = .F.
.Italic = .F.

ENDWITH

Hope this helps!

- della


>I just reviewed my code and found the syntax error:
>Below I typed
>
>oDoc.tables(lncustomertbl).cell(lncustcntr,5).range(wdCollapseend)
>
>when I should have typed:
>
>oDoc.tables(lncustomertbl).cell(lncustcntr,5).range.collapse(wdCollapseend)
>
>But I still don't know what the code is to accomplish what I need. The code I have now makes everything non-bold, non-italic. I need to select the first line of text, then make it bold. Then I need to set a new range on the remaining text, and apply bold to that.
>
>
>
>
>>I am attempting to change the text formatting of text that is within a cell of my table, via word automation. The code I have tried so far does not work. Here is what I want to do:
>>
>>I want to have the first line of text in my cell in bold and italics, then issue a carriage return, and then have the remaining text not bold, not italicized.
>>The code I tried does not work - see below. the 'wdcollapseend' line gives me the error message 'does not support a collection'
>>
>>What is the proper syntax to get this to work?
>>
>> oDoc.tables(lncustomertbl).cell(lncustcntr,5).range.text=alltrim(currespmatr_customer.mrecommend)+ chr(13)
>> oDoc.tables(lncustomertbl).cell(lncustcntr,5).range.bold= .t.
>> oDoc.tables(lncustomertbl).cell(lncustcntr,5).range.italic= .t.
>> *oDoc.tables(lncustomertbl).cell(lncustcntr,5).range(wdCollapseend) && got error 'does not support a collection'
>> *oDoc.tables(lncustomertbl).cell(lncustcntr,5).range.bold= .f.
>> *oDoc.tables(lncustomertbl).cell(lncustcntr,5).range.italic= .f.
>> oDoc.tables(lncustomertbl).cell(lncustcntr,5).range.insertafter(alltrim(currespmatr_customer.mconcept))
>>
>>
>>TIA
Previous
Reply
Map
View

Click here to load this message in the networking platform