Results 1 to 6 of 6

Thread: A general question about Word application

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Posts
    29

    Red face 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.

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    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".

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Posts
    29
    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

  4. #4
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    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:
    1. Option Explicit
    2.  
    3. Dim mum As Integer
    4.  
    5. Sub PopulateMyCombo()
    6.  
    7.     With ComboBox1
    8.         .Clear
    9.         .AddItem "John":    .Column(1, 0) = "Vocals"
    10.         .AddItem "Paul":    .Column(1, 1) = "Bass"
    11.         .AddItem "George":  .Column(1, 2) = "Guitar"
    12.         .AddItem "Ringo":   .Column(1, 3) = "Drums"
    13.     End With
    14.  
    15. End Sub
    16.  
    17. Private Sub ComboBox1_Click()
    18.  
    19.     mum = mum + 1
    20.  
    21.     With ActiveDocument.Tables(1)
    22.         .Cell(mum, 1).Range = ComboBox1.Value
    23.         .Cell(mum, 2).Range = ComboBox1.Column(1, ComboBox1.ListIndex)
    24.     End With
    25.  
    26. End Sub
    Run the PopulateMyCombo sub first. Now you can click the combo in the document to ad the data to the table.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Posts
    29

    Red face

    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!!

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2001
    Posts
    29
    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
  •  



Click Here to Expand Forum to Full Width