PDA

View Full Version : ActiveX Textbox in Word



Dubravak
07-08-2015, 12:42 PM
Hi guys,

can anybody help me how I can programme a created ActiveX Textbox (e.g. TextBox5_Change() ). This textbox will be also created by subroutine first. I used code: ActiveDocument.Tables(1)Rows(2).Cells(1).Range.InlineShapes.AddOLEControl ClassType:="Forms.TextBox.1" but next I cant move with that.

In the macro I am creating a table, in which an ActiveX Textboxes will be added. Typing text in the table will be automatic used for some goals, so for this reason I want to use ActiveX textbox. But maybe its wrong way :) I dont know another way to get the table cells value in Word :-/

Table will be created according to parameters entered, so I cant do it with using a tools (by clicking), I have to programme all :)

PS: Hope, its understandable.

Thanks

gmayor
07-08-2015, 11:48 PM
Let me get this clear.
1. You are creating adding to the table from code?
2. You are adding a text box (or boxes) to the table to accept text?

What I don't understand is "Typing text in the table will be automatic used for some goals". What does that mean in this context? Are you typing text from the keyboard into the table, or you are adding text to the table in code. What is the purpose of the text box? You can add/edit text directly in the table, or if you want to add a place marker, use a content control.

e.g.

Dim oTable As Table
Dim oCell As Range
Set oTable = ActiveDocument.Tables.Add(ActiveDocument.Range, 2, 2)
Set oCell = oTable.Rows(2).Cells(1).Range
oCell.End = oCell.End - 1
oCell.Text = "This is text in row 2 cell 1"

Dubravak
07-09-2015, 12:28 AM
Sorry for less understandable.

I need make a word document, where it will be an active combobox with 2-5 items. Depends on this choice, it will be the table created/displayed. Items 2-5 represents a number of rows in the table.

Next I need set up some cells of this table in the way, that typing text into table from the keyboard causes automatically used the data (letters) and copy to another place in the document. So for this purpose I want to use activeX textbox in the cells. But maybe it is not best idea...? :-)

Is that more clearer? Thanks

Thanks.

gmayor
07-09-2015, 12:57 AM
OK I think I see where you are going. However the following remains unclear. If there is a variable number of rows, and thus presumably a variable number of places to enter the texts, how do you intend to determine where those texts are repeated later in the document? For this type of document, it would be better to create a userform to make the selections and write the values to appropriate places in the document. At its most basic, see http://www.gmayor.com/Userform.htm

Dubravak
07-09-2015, 02:28 AM
Thank you gmayor for your reply.

How do I intend to determine where those texts are repeated later... simple, there will be another activex textboxes, where a text will be transfered from the table. But these textboxes would be much easier, because I can add them using clicking tools. And at last just set up visibility/hiding/locking - depends on condition at combobox.

I am not sure, if a userform would help me now. A document is already quite constructed. Therefore I am looking for a way, how I can get the cells value of word table to another place in document. And any type-change in the cells will be automatically updated in the document at all.

Second idea I have is preparing all 4 options (4 tables with 2 - 5 rows), add ActiveX Textboxes in the cells manually (clicking) and set up visibility/hiding/locking of all tables. So the code would not create a table, but just display what is right.
But problem is that i dont know, how to hide all table/tables and disable it :)

Thank you.