|
-
Nov 15th, 2003, 11:29 AM
#1
Thread Starter
Junior Member
A general question about Word application
Hello
I am not very sure that whether user can add any features, for example, add a Combo box direct into a Word document, (I guess Not), or user has to run a Macro through creating a Form and add Combo box into the Form? It sounds stupid but I need to make sure with it.
My idea is that when user fill in a table in a Word document, using Combo box to provide user some predefined information, user click the select information and fill it into the table in Word.
Such Combo box can appear in Word document directly or by runing a Macro?
Any ideas? Thanks in advance.
-
Nov 16th, 2003, 12:28 PM
#2
Fanatic Member
There are two ways to do this. From the Forms toolbar, you can ad a Drop-Down Form Field. This adds a drop down field tha you can add values to. This can be usd on a protected form so that the user can only modify form fields. For more info, see Word Help topic "Form fields in forms".
You can also add a regular VB combobox from the Visual Basic toolbar. You ca put this right into a Word document. This will require coding. For more info, see Word Help topic "ActiveX controls in forms".
-
Nov 16th, 2003, 01:32 PM
#3
Thread Starter
Junior Member
Dear WorkHorse
Thank you very much for your valuable help every time.
I tried to add a drow-down Form Field from Form toolbar into a Word doc., however the Field doesn't look like a proper drow-down field, it looks more like a button. I don't know how I can list my predefined data in such drow-down field.
I added a vb ComboBox in a created UserForm, when I run this Macro, the Form appear in Word document, meanwhile the ComboBox in the Form list the data. So far, it is ok.
next step, I want to:
select data in the ComboBox
fill the data into first row in the table in Word
select different data in the ComboBox
fill the data into second row in the table in Word
'''''
My code:
Private Sub okButton_Click()
Dim rng As Range
Dim agTable As Table
Dim C As Integer
Dim rnum As Integer
Dim R As Integer
Set agTable = Selection.Tables(1)
rnum = agTable.Rows.Count
For R = 2 To rnum
agTable.Cell(R, 1).Range.InsertAfter cboAgentName
agTable.Cell(R, 2).Range.InsertAfter cboAgentType
Next R
End Sub
cboAgentName and cboAgentType are the data in ComboBox
I know this code is not right, it will add same data selected into all table cells, this is not what i want. I need the data selected every time into different cell.
I have tried bookmarks, but it is a good idea to bookmark all cells in the table.
My table is quite sample, only have two columns, any possibility to use column name to indicate which column the data should be inserted automatically after other data in that column,
or use Cursor to indicate where? I can find any Cursor methods.
Sorry for my English and I hope I have confused you.
Any idea please!! Thank you in advance.
Claire
-
Nov 16th, 2003, 02:26 PM
#4
Fanatic Member
I'm not sure I quite follow. Do you have the Name and Type in a combobox and you want to add these to a table as the users clicks on them? Like this:
VB Code:
Option Explicit
Dim mum As Integer
Sub PopulateMyCombo()
With ComboBox1
.Clear
.AddItem "John": .Column(1, 0) = "Vocals"
.AddItem "Paul": .Column(1, 1) = "Bass"
.AddItem "George": .Column(1, 2) = "Guitar"
.AddItem "Ringo": .Column(1, 3) = "Drums"
End With
End Sub
Private Sub ComboBox1_Click()
mum = mum + 1
With ActiveDocument.Tables(1)
.Cell(mum, 1).Range = ComboBox1.Value
.Cell(mum, 2).Range = ComboBox1.Column(1, ComboBox1.ListIndex)
End With
End Sub
Run the PopulateMyCombo sub first. Now you can click the combo in the document to ad the data to the table.
-
Nov 19th, 2003, 10:01 AM
#5
Thread Starter
Junior Member
Hi WorkHorse
I have two Combo Boxes called cboAgentName and cboAgentType in the UserForm called GetAgentList. When I select the a AgentName from cboAgentName and a AgentType from the cboAgentType, I want the selected AgentName and AgentType added in a Table in Word once a row when a OKbutton clicked. My table is like below
AgentName AgentType
Polit Human
Aircraft Machine
The data should be added once a row when every Ok clicked. For example, I select AgentName=Polit, AgentType=Human in Combo Box, when I click Ok, the "Polit" and "Human" should be inserted in first row in the table, then I select AgentName=Aircraft, AgentType=Machine, click Ok again, the "Aircraft" and "Machine" should be in second row, so on.
My problem is that I could NOT insert the data once a row, the code can not return value for R, how can i increment value of R by 1, when Ok clicked every time.
Set agTable = Selection.Tables(1)
R = R + 1
agTable.Cell(R, 1).Range.InsertAfter cboAgentName
afTable.Cell(R, 2).Range.InseertAfter cboAgentType
I tried your code below, but it seems that the variable mum also can not increment by 1.
Please help!!
-
Nov 20th, 2003, 09:40 AM
#6
Thread Starter
Junior Member
I find a way to solve this.
dim r as integer
dim agTable as Table
set agTable = Selection.tables(1)
r=agTable.rows.add.index
agTable.Cell(r, 1).Range.InsertAfter cboAgentName
afTable.Cell(r, 2).Range.InseertAfter cboAgentType
This code will add the selected data in Combo box into a new row in Word table every time.
Any other better ideas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|