Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
checkboxes in word documents

Subject: checkboxes in word documents

From: Michael

Date: 14 Jul, 2010 22:33:06

Message: 1 of 7

Hello,

I need to check and uncheck check box form field objects in a word document.

I got this far:

docFilename = 'TEST check box form.doc';
hdlActiveX = actxserver('Word.Application');
hdlActiveX.Visible = true;
trace(hdlActiveX.Visible);
hdlWordDoc = invoke(hdlActiveX.Documents, 'Open', docFilename);
h=invoke(hdlWordDoc.Bookmarks,'Item','Check1');
set(h.Range.FormFields.Shaded,0);

This works. It un-shades the checkbox.

These do not:


>> set(h.Range.FormFields(1),'Value',0)
??? Invoke Error: Unknown name or named argument
 
>> set(h.Range.FormFields(1),'Result',0)
??? Invoke Error: Unknown name or named argument


Thanks in advance.

Subject: checkboxes in word documents

From: Michael

Date: 15 Jul, 2010 12:04:05

Message: 2 of 7

"

Subject: checkboxes in word documents

From: Yair Altman

Date: 15 Jul, 2010 14:09:06

Message: 3 of 7

> >> set(h.Range.FormFields(1),'Value',0)
> ??? Invoke Error: Unknown name or named argument


try this:
set(h.Range.FormFields.item(1),'Value',0)

Yair Altman
http://UndocumentedMatlab.com

Subject: checkboxes in word documents

From: Michael

Date: 15 Jul, 2010 15:03:19

Message: 4 of 7

Dear Mr. Altman,

Thank you for responding. I visit your website often.

This is a serious problem for me, I will have to rewrite my project in another language if I cannot solve it.

Unfortunately, your suggestion did not work for me.

Best,

Michael

P.S.,

>> set(h.Range.FormFields.item(1),'Value',0)
??? No appropriate method, property, or field item for class Interface.Microsoft_Word_12.0_Object_Library.FormFields.
 

>> h.Range.FormFields.item
??? No appropriate method, property, or field item for class Interface.Microsoft_Word_12.0_Object_Library.FormFields.
 
 
>> get(h.Range.FormFields)
    Application: [1x1 Interface.Microsoft_Word_12.0_Object_Library._Application]
        Creator: 1.2973e+009
         Parent: [1x1 Interface.Microsoft_Word_12.0_Object_Library.Range]
          Count: 1
         Shaded: 1

Subject: checkboxes in word documents

From: Andy

Date: 15 Jul, 2010 15:41:04

Message: 5 of 7

% Some sample code
% note: before running, create a word document with a check box in it

[fn,pn] = uigetfile('*.doc');
w = actxserver('Word.Application');
w.Visible = true;
d = w.Documents.Open([pn fn]);
ff=d.FormFields;
cb = ff.Item(1);
cb.CheckBox.Value = true; % <- Check Box is checked
cb.CheckBox.Value = false; % <- Check Box is unchecked

Subject: checkboxes in word documents

From: Michael

Date: 15 Jul, 2010 15:53:04

Message: 6 of 7

That worked.

Thank you both very much.

Subject: checkboxes in word documents

From: Yair Altman

Date: 15 Jul, 2010 19:56:22

Message: 7 of 7

> Unfortunately, your suggestion did not work for me.
>
> >> set(h.Range.FormFields.item(1),'Value',0)
> ??? No appropriate method, property, or field item for class Interface.Microsoft_Word_12.0_Object_Library.FormFields.
>
> >> h.Range.FormFields.item
> ??? No appropriate method, property, or field item for class Interface.Microsoft_Word_12.0_Object_Library.FormFields.

Minor correction: Item(1), not item(1)
Item is a method, not a property, therefore you need to use methods(h.Range.FormFields), not get(h.Range.FormFields)

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us