cancel
Showing results for 
Search instead for 
Did you mean: 

How to check checkbox in MS Word?

AstridStollberg
Level 6
Dear wise community,

I'm trying to use MS Word VBO - set selected checkbox action in order to check a checkbox in a word document but it doesn't work for me.
For testing, I created a simple document which only contains text "Test" and after that a checkbox.
I open the document manually and attach to it using MS Word VBO - attach instance action.
Then I use "find text" action and search for "Test". I can see in the document that the text gets selected in the word document. 
Then I use "Select next field" (which returns Selected=True), but I don't see anything happening in the word.
Then I use "Set selected checkbox" with parameter Checked=True, but again, nothing happens in the document...

Any idea what I'm doing wrong?

What is actually considered a "field" in word?
In another (bigger) document, when I tried the "Select next field" and then "Type Text", I noticed that it selected some hyperlink and overwrote this then with my text...

Appreciate your help!

Cheers
Astrid
Cheers [FirstName]
3 REPLIES 3

Hi, Astrid,

I think that your understanding is not correct. Checkbox is different type of element within Word instance. It is so called control element so it differs from text which is written on the page. As I worked in the past with MS Word quite extensively for one bank I updated our current NEOOPS VBO with a new action to get all checkboxes which are within the document. The action returns collection of checkboxes with status (True - checked, False - unchecked), checkbox ID and checkbox title. I am attaching the code for this action. The only modification to Blue Prism default MS Word VBO is that you need to add reference to your Microsoft.Office.Interop.Word. See attached screen shot. Please be aware that your path to the dll file may differ.

If you need more please let me know through PM.




Regards,

Zdenek

AstridStollberg
Level 6
Hey Zdenek,

many thanks for your quick reply!

I'll look into your process/object next week.
However, I've been looking for the NEOOPS VBO in Blue Prism DX but I couldn't find it , only the "NEOOPS MS Outlook VBO" (I tied to attach a screenshot but doesn't work for me somehow....).
Could you maybe check if it's published correctly?

Many thanks & happy weekend 🙂
Astrid​
Cheers [FirstName]

AstridStollberg
Level 6
Dear Zdenek,

I had some issues with your VBO - I believe some code was missing in the global code section and a also page...

However, I googled myself a bit and managed to implement my own Word VBO which supports the basic functionality that we need for the current automation project.
  • Open document (to create a Word instance and open a Word document)
  • Close document (to close both the word application and document)
  • Get Checkbox Status (returns whether the checkbox is checked or not)
  • Set Checkbox Status (can be used to set checkbox checked/unchecked)
  • Get Text from Textfield (returns value a certain textfield holds)
  • Set Text for Textfield (sets the text for a certain textfield)

Checkbox and Textfield must be of type content control and have a title by which the control can be identified.

Same reference to Microsoft.Office.Interop.Word.dll would be needed and I put everything in the global code and call the respective methods then from code stages in the respective actions.
Here's how my global code looks like:

static Application ap;
static Document document;

static void OpenDocument(string fileName)
{
	ap = new Application();
	document = ap.Documents.Open(fileName);
	//ap.Visible = true;
}

static bool getCB_checked(string cb_Title)
{
	//Output
	bool isChecked = false;

	ContentControls controls = document.SelectContentControlsByTitle(cb_Title);
	foreach (ContentControl cb in controls)
	{
		isChecked = cb.Checked;
	}
	return isChecked;
}

static void setCB_status(string cb_Title, bool cbChecked)
{
	ContentControls controls = document.SelectContentControlsByTitle(cb_Title);
	foreach (ContentControl cb in controls)
	{
		cb.Checked = cbChecked;
	}
}

static void closeDocument()
{
	ap.Documents.Close(WdSaveOptions.wdSaveChanges);
	ap.Quit(WdSaveOptions.wdSaveChanges);
}

static string getTextFromTextfield(string textFieldTitle)
{
	//Output
	string text = "";

	ContentControls controls = document.SelectContentControlsByTitle(textFieldTitle);
	foreach (ContentControl cb in controls)
	{
		text = cb.Range.Text;
	}
	return text;
}

static void setTextForTextfield(string textFieldTitle, string text)
{
	ContentControls controls = document.SelectContentControlsByTitle(textFieldTitle);
	foreach (ContentControl cb in controls)
	{
		cb.Range.Text = text;
	}
}​


Anyway, thanks for your help 🙂

Cheers [FirstName]