Hello everyone
I am trying to add a checkbox to a table and then set its name and check it. I manage to add it but when I try to use the checkbox I get "Object variable or with block variable not set"
I use vba in excel to create a word document and manipulate it
The relevant code is this:
I tried changing the with block toDim wrdApp As Word.Application Dim wrdDoc As Word.Document Set wrdApp = CreateObject("Word.Application") Set wrdDoc = wrdApp.Documents.Add wrdApp.Visible = True Dim docRange As Word.Range Set docRange = wrdDoc.Range docRange.Collapse Direction:=wdCollapseEnd docRange.InsertParagraphAfter docRange.Collapse Direction:=wdCollapseEnd Dim tbl As Word.Table Set tbl = wrdDoc.Tables.Add(docRange, 8, 3) With wrdDoc.FormFields.Add(Range:=tbl.Cell(7, 2).Range, Type:=wdFieldFormCheckBox) .name = "BoxName" ' HERE is where I get the error .CheckBox.Value = True End With
But then I get "Method or data member not found" error.Dim box As Word.CheckBox Set box = wrdDoc.FormFields.Add(Range:=tbl.Cell(7, 2).Range, Type:=wdFieldFormCheckBox) box.name = "BoxName" ' HERE is where I get the error box.CheckBox.Value = True
What am I doing wrong?
Thanks in advance
Last edited by Brunstgnegg; 08-11-2010 at 03:19 AM.
I had this answered in another subforum. The trick is to collapse the range of the cell before adding the checkbox.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks