Object Required Error

  • Thread starter Thread starter Owen
  • Start date Start date
O

Owen

Hello

I am attempting to use a macro to insert a combobox within a table in my
document. I am getting an error at,

cboNew = Document.Controls.Add("Document.Combobox.1", "cboNew")
which responds with "object required".

I am new to programming and can't work out the error. I have attached my
full code below.

Sub Macro4()
ActiveDocument.Unprotect
Selection.GoTo What:=wdGoToBookmark, Name:="Equipment_Software"
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
Selection.Copy
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCell
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Set cboNew = Document.Controls.Add("Document.Combobox.1", "cboNew")
With cboNew
..AddItem " "
..AddItem "AP Long Range Wireless LAN"
..FontName = "Arial"
..FontSize = "8"
..Width = 250
End With
End Sub

Can anyone tell me where i am going wrong?
Thanks Owen
 
There is no Controls.Add command, but in addition to that, you would need to
use ActiveDocument, not just Document

If you are using Word 2007, you can use

ActiveDocument.ContentControls.Add(etc.)

Otherwise

ActiveDocument.FormFields.Add

Check out the Visual Basic help file for whichever is applicable.

--
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
 
Back
Top