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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing TEXTBOX text

Status
Not open for further replies.

csr

Programmer
Jul 20, 2000
507
I have a document in which there exists a textbox with some text in it. I am using automation to add text to the document but would also like to change the text within the textbox on a particular page or section. My problem is that I have no idea how to address the textbox. It was part of a template (.dot) file that I used to begin the automation.

I have tried using a macro to find out but each time I turn on a macro, the textbox disappears so I am unable to do anything which will allow me to see the code behind it.

Any ideas ?




Don


 

Don,

You didn't mention which application you are automating. I assume from your reference to DOT files that it is Word.

If so, a textbox is a type of shape. The document has a Shapes collection. Each Shape object has a Type property. If the Type is 17, then the shape is a textbox.

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Well, it is a step in the right direction.

I will try something to this effect ...

for j = 1 to <number of shapes>
if oDoc.Shapes[j].type = 17
if oDoc.Shapes[j].text = "Old Text"
oDoc.Shapes[j].text = "New Text"
endif
endif
endfor

At this time, I do not know how I will determine <number of shapes but I may be able to come up with something in my research effort. I am not sure of any of the syntax but that too may surface.

Thanks for your help




Don


 
Great. Thanks Again.

I will give it a try.



Don


 
Well, it turns out that the textbox is not in the document but is in the header. So I have the following code which the computer chokes on the the line with the 17 in it.

The error is ... ITEM does not evaluate to an object.

Apparently, within the header, there is no direct Shapes.Type ( I tried that ) so I found this sequence of properties but still no cigar.

WITH oDoc.Sections.Last.Headers[wdHeaderFooterPrimary]
nShapes = .Shapes.count
FOR j = 1 TO nShapes
IF .Shapes.item.Type = 17
* Assign the Text to the textbox here
ENDIF
ENDFOR
ENDWITH




Don


 
You need to address a particular shape:

Code:
 IF .Shapes[j].Type = 17

Tamar
 
Ok, I am back on task. Will let you know how it comes out.
Thanks.

Don


 
Well, here is where I am now ...

The following code works until it hits the code where I assign the text to the shape. It chokes on that.


WITH oDoc.Sections.Last.Headers[wdHeaderFooterPrimary]
nShapes = .Shapes.count
FOR j = 1 TO nShapes
IF .Shapes[j].Type = 17
.Shapes[j].Text = "Confidentiality"
ENDIF
ENDFOR
ENDWITH


Don


 
That's because the Shape object doesn't have a Text property.

Now that I'm thinking about this, I don't know that Shapes is where you want to be for Textboxes. Try using the FormFields collection instead.

If you have FoxPro Advisor, take a look at my Advisor Answers piece in the April, 2004 issue.

Tamar
 
Well, this is proving to be very illusive.
The following code does not execute anything inside the FOR loop because nFormFields was Zero.

also ... I used debug to determine that oDoc.Shapes.count was also zero.

I know there is a textbox in the document because I can see it and edit it. Any ideas what it is called ?



nFormFields = oDoc.FormFields.count
FOR j = 1 TO nFormFields
oFormField = oDoc.FormFields[j]
IF oFormField.Type = 17
oFormField.Range.Text = "Confidentiality"
ENDIF
ENDFOR


Don


 
If you're in VFP 7 or later, try playing around with it in the Command Window (with IntelliSense) to figure out which collection is holding the thing.

Tamar
 
Well, I have done that inside of debug. I tried traversing through everything (Shapes,Formfields, & InlineShapes) that looked like it could be a collection to see where it led. Is there any means of telling which things are collections or do I have to just keep browsing through things until I hit something ?

Don


 
Take a look at the object model diagram in the Word VBA Help file. That'll give you some clues. You could also use the Object Browser either in Word's VBA or in VFP to explore the object model.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top