Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Add combobox into table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kdyjur@gmail.com - 16 Sep 2006 05:01 GMT
OK, I have a table where I click a button and it adds a row on the
bottom of the table. There are four columns in that row and I want to
place a combobox in column three of the new row.

I have looked everywhere and still cannot get the syntax 100% right:

Private Sub butAddTask_Click()
   '1. Add Row
   ActiveDocument.Tables(1).Rows.Add
   '2. Count Rows
   intNumberOfRowsTasks = (ActiveDocument.Tables(1).Rows.Count)
   '3. Write Text into Cells
   Tables(1).Cell(intNumberOfRowsMilestones, 3).Range.Text =
InlineShapes.AddOLEControl(ClassType:="Forms.ComboBox.1",Tables(1)(intNumberOfRowsMilestones,
3))

End Sub

Basically it's the third part of this that I want to get straight.
additionally I want to add four items to this new combobox. Can someone
PLEASE help???
Helmut Weber - 16 Sep 2006 06:09 GMT
Hi,

this is working for me here and now:

Sub Macro2()
Dim r As Long
With ActiveDocument.Tables(1)
  .Rows.Add
  r = .Rows.Count
  .Cell(r, 3).Select
  selection.Collapse
  selection.InlineShapes.AddOLEControl ClassType:="Forms.ComboBox.1"
  With selection.InlineShapes(1).OLEFormat.Object
     .AddItem "0001"
     .AddItem "0002"
     .AddItem "0003"
  End With
End With
End Sub

Might be possible do avoid the selection-object,
but I think it isn't relevant here.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Doug Robbins - Word MVP - 16 Sep 2006 07:28 GMT
This uses the Range object rather than the Selection object

Dim r As Range
With ActiveDocument.Tables(1)
  .Rows.Add
  Set r = .Cell(.Rows.Count, 3).Range
  ActiveDocument.InlineShapes.AddOLEControl ClassType:="Forms.ComboBox.1",
Range:=r
  With r.InlineShapes(1).OLEFormat.Object
     .AddItem "0001"
     .AddItem "0002"
     .AddItem "0003"
  End With
End With

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi,
>
[quoted text clipped - 18 lines]
> Might be possible do avoid the selection-object,
> but I think it isn't relevant here.
kdyjur@gmail.com - 16 Sep 2006 15:36 GMT
Both methods work equally as well. Thank-you gentlemen!! Would it
surprise you to know that I've been trying to come up with that on my
own for three days now? I'm new to VBA, so this is really a help.

I have this sub in there as well which I would like to fire for
"Combobox1", but other combobox's as well. Is there a way to make it
portable to new combobox's?

Private Sub ComboBox1_Change()
   If ComboBox1.Text = "Addressed" Or ComboBox1.Text = "No Flag" Then
       ComboBox1.BackColor = RGB(184, 225, 127)
       ComboBox1.ForeColor = RGB(0, 0, 0)
   ElseIf ComboBox1.Text = "Follow-Up" Then
       ComboBox1.BackColor = RGB(73, 22, 109)
       ComboBox1.ForeColor = RGB(255, 255, 255)
   ElseIf ComboBox1.Text = "Waiting" Then
       ComboBox1.BackColor = RGB(250, 202, 0)
       ComboBox1.ForeColor = RGB(0, 0, 0)
   End If
End Sub

> This uses the Range object rather than the Selection object
>
[quoted text clipped - 49 lines]
> > Win XP, Office 2003
> > "red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 16 Sep 2006 20:29 GMT
Hi,

>I have this sub in there as well which I would like to fire for
>"Combobox1", but other combobox's as well. Is there a way to make it
>portable to new combobox's?

writing code which manipulates code is possible, in principle.
You need a reference to the appropriate library.
Which was
microsoft visual basic for applications extensibility library 6.0,
or so, seemably in other versions than the one I got at present,
because I can't it anymore.

But it's hell, I'd say.

I did some experiments with it years ago.
But as it was to me of little practical use,
I forgot about it.

Another way would be, to use a selection-change event
and loop over all inlineshapes of
OLEFormat.ClassType = "Forms.ComboBox.1".

But it would terribly slow down editing. probably.
Maybe feasable for 1 page documents.

Or you mean something like that:

Private Sub ComboBox1_Change()
  Combo
End Sub

Private Sub Combo()
Dim oCtrl As InlineShape
For Each oCtrl In ActiveDocument.InlineShapes
  If oCtrl.OLEFormat.ClassType = "Forms.ComboBox.1" Then
     If oCtrl.OLEFormat.Object.Text = "0001" Then
       oCtrl.OLEFormat.Object.BackColor = RGB(184, 225, 127)
       oCtrl.OLEFormat.Object.ForeColor = RGB(0, 0, 0)
     End If
     ' ... more conditions and actions
  End If
Next
End Sub

I'm at the end of my wisdom, sorry.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Ted Williams - 17 Sep 2006 04:16 GMT
Thank you Helmut, this was actually greatly helpful. I just added a
command button to the form and when it is clicked, your sub is called.
It takes all of the combos and evaluates the text and colours the
accordingly.

Thanks again for taking the time to write good responses. I have
learned! Greetings from Canada.

> Hi,
>
[quoted text clipped - 50 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.