Most Valuable Professional


View Jan Karel Pieterse's profile on LinkedIn subscribe to rss feed
Subscribe in a reader

Subscribe to our mailing list

* indicates required

File crashes Excel!!

Save my workbook!
The best tool for salvaging problematic workbooks.

Trainings

Excel VBA Masterclass (English)
Excel VBA for Financials (Dutch)

Third party tools

Speed up your file

FastExcel
The best tool to optimise your Excel model!

Repair your file

Stellar Phoenix Excel Repair
Best tool to repair corrupt Excel sheets and objects
Home > English site > Articles > Excel 2007 FileFormat > Form Controls
Deze pagina in het Nederlands

The New Excel 2007 File Format

Changing properties of Form controls

I was curious how Form controls are represented in the Excel 2007 file format, so I started a journey searching for them.

Demo file

I have devised a small file with this on Sheet1:


Demo file showing a couple of Form controls

Where Form controls are stored

If you rename the xlsx file to xlsx.zip you can open the package and look inside. Open the folder xl and then the folder Worksheets. Open sheet1.xml. Near the bottom of that file, you can find this entry:


Bottom section of sheet1.xml, highlighting the reference to the form controls file.

To find out what rId2 points to, open the _rels folder:


Window of opened zip container showing the worksheets\_rels folder

Open the sheet1.xml.rels folder and find rId2:


Highlighted relevant portion of sheet1xml.rels

So now we know we need to navigate up the folder tree and find ..\xl\drawings\vmlDrawing1.vml.

VML files

There is one vmlDrawing?.vml for each worksheet that contains controls (or any other object that is captured in this vml file).

According to the Open XML specification document as it was made available at ecma (look for the "mark up language reference"), VML is described as:

"Vector Markup Language (VML) is an XML-based exchange, editing and delivery format for high-quality vector graphics. VML facilitates the exchange and subsequent editing of vector graphics between a wide variety of productivity and design applications. VML is based on XML 1.0, which is an open, simple, text-based language for describing structured data. "

Form controls in a VML file.

Drag the vml file from the explorer window on to your desktop and open the vml file.

If try to you open the vml file in Internet explorer (because it so prettily colours and indents xml) you get an unpleasant surprise, IE asks you whether it should download or save the file, putting you in an endless cycle unless you choose cancel. Luckily there is a tool called "XML notepad" (free download), which shows the xml in various ways. Here is the tool showing the xml portion of the checkbox:


XML Notepad showing the (formatted) xml part of a checkbox from the forms toolbar on an Excel sheet

Hey! what is that font node doing up there? For over a decade I've been telling people you cannot change a form's checkboxes font. Can you? Let's just try.

Changing the font of a checkbox (from the forms toolbar)

Note (2013-01-15): It seems that the behavior described below has been changed. If you use Excel 2010 to open a file changed using this trick, the font properties of the checkbox are no longer affected (which makes sense in a way, because you can also not change them from the user interface). If opened with Excel 2003, even stranger things happen, I got an extra checkbox control in my Excel 2003 when I changed the Font name of the VML file of the download to 'Courier New'.

Switch to the treeview tab of XML notepad (if you're using that too) and edit the font face property and the size. I changed it to:

<font face="Arial Black" size="320" .....

Lets see what that did to our file. Follow these steps:

Surprise, surprise, your checkbox now looks like this:

Forms checkbox in Excel with modified font

Lets stretch our luck a bit. Save the file as 97-2003 file format. Now try to open it in any of those formats (I tried 2003). Well, surprise, surprise, it sticks!

Changing a control's position

The position of  control is denoted by the Anchor node inside the control's set of nodes:


XML from the vmlDrawing1.vml file with size and position part highlighted

So what does this mean? The first two numbers tell us where the top-left corner of the control is horizontally: the column (zero based) and the offset from the start of the left of that column. The next two numbers represent the row number (again, zero based) and the offset downwards (pixels) from the top of that row. The next four do the same for the bottom-right corner.

In other words, in the xml above, the control's top-left corner is in column E, row 3. It is shifted to the right by 29 pixels. And the bottom-right corner is in cell I4, shifted 38 pixels to the right and 18 downwards, relative to that cell's top-left position.

Well, that's it. I hope I have given you a head start on working with form controls in the new Excel 2007 Open XML file format. I leave it up to you to figure out what the other nodes in the vml file are for.

Download

I have made the file used in this article available for download:

FormControls.zip


 


Comments

All comments about this page:


Comment by: OVGuillermo (8/27/2007 12:09:00 PM)

Thank you for your site. I have found here much useful information.
Good site ! ;)

 


Comment by: Dinesh (6/25/2008 2:01:04 AM)

This is pretty use ful stuff for someone who is looking to modify an existing excel
tool to excel 2007. But when i try the above steps i ended up with an error
saying "one of the files got corrupted" or "run time error" .. can you help me on
this regard. After editing the fields required and saving it from .xmls.zip
to .xmls getting a runtime error.

 


Comment by: Jan Karel Pieterse (6/25/2008 3:06:19 AM)

Hi Dinesh,

When do you get these messages, when loading the file after modifications? What did
you modify?

 


Comment by: Kalpana (8/19/2008 12:43:11 PM)

Thank you very much for this informative site. Though the ECMA standards have it
all, its better to read such explanations of it with an example. You made my day :-)

 


Comment by: Kalpana (9/9/2008 11:06:59 AM)

Nice information. Was planning to write down something similar in my blog for other
souls who have to parse SpreadsheetML files.

Regards,
Kalpana

 


Comment by: Jan Karel Pieterse (9/9/2008 10:21:55 PM)

Hi Kalpana,

Thanks. Let me know if/when something has been published.

 


Comment by: Dan (9/22/2008 9:27:20 PM)

I've been trying to use this method to create a dropdown combobox form control with
background color orange. It is white by default and cannot be changed from the form
control properties. The problem is I don't see a field in the VML that corresponds
to the background color. Any ideas?

 


Comment by: Jan Karel Pieterse (9/23/2008 1:24:12 AM)

Hi Dan,

Looks like you can't change that for a dropdown indeed. The text formatting
properties are not available.

 


Comment by: Dan (9/23/2008 3:50:56 PM)

Thanks. I was hoping that this can be done by formatting the cell behind the
control to orange and chaning the order. It seemed that you should be able to do
it, but in reality the "order" doesn't do antyhing. The control is always hiding
whatever is behind it and there's nothing you can do to change its color indirectly
via the cell underneath.

 


Comment by: Laithoron (9/26/2008 8:39:48 PM)

Good find on how to change the text for the checkbox. Is it possible to change the
size of the actual checkbox itself, and if so how?

 


Comment by: Jan Karel Pieterse (9/28/2008 12:00:32 PM)

Hi Laithoron,

The information is embedded in the x:Anchor attribute.
I describe the meaning of the numbers just above the "Download" heading on this page.

 


Comment by: Hari singh chauhan (4/16/2009 10:26:03 PM)

Thanks , but I have a problem for representing Controls Object with DML . when I create excel file in window and than open same file on Mac and also reverse than Controls does not comes proper place when any graphics behind that Control Object that time Control Object looks misplace . it happens when graphics intersect to Control Object. also that time Graphics size increases and cell width and height increases so Please gives some ideas. How can solve this problem

 


Comment by: Jan Karel Pieterse (4/17/2009 3:51:57 AM)

Hi Hari,

Not sure I understand. You have an Excel 2007 file with controls which look odd on MAC Excel?
WHat happens if (from Excel 2007) you save the file as Excel 97-2003 format?

 


Comment by: hari singh chauhan (4/17/2009 9:59:47 PM)

Thank you sir for reply.
When i create any file in Excel 2007 Window which contain graphics shape and control objects like Button,Checkbox etc. but control objects intersect and place inside at graphics shape . than open same file on Mac OS . it will look control objects misplace our position and increases size . if we will take two and three control objects and graphics shape which intersect to each other than we can see it properly . so i am not able to represent graphics shape and control objects same just like to window show it.

 


Comment by: Jan Karel Pieterse (4/19/2009 7:17:50 AM)

Hi Hari,

I don't think there is much you can do about this except trying different setups and controls until you find a combination that works on both platforms.
Tedious, but I see no other way.

 


Comment by: jyoti bulchandani (7/31/2009 12:03:41 AM)

Hi,
can u plz let me know how to change the backgroung color of the listbox form control.

 


Comment by: Jan Karel Pieterse (7/31/2009 3:15:19 AM)

Hi Jyoti,

I don't think that is possible with forms controls. Maybe with the control toolbox control you can?

 


Comment by: norman (2/2/2010 3:51:47 AM)

amazing, thank you so much!!!

 


Comment by: Brian Skromme (2/10/2010 11:45:34 AM)

I find a weird bug with Form Controls on chart sheets in Excel 2007. When I first open a workbook created in Excel 2003, the chart sheet that was active when I last saved the file (in Excel 2003 format) does not show the form controls (they appear invisible). When I go to another sheet and change the state of a checkbox there (with Visual Basic behind the controls), then go back to the first sheet, they are now visible (though this depends on which sheet was active when saved). Problem does not occur in Excel 2003. (Of course, there are innumerable other problems that pop up only in 2007 also!!) Any ideas? Installing the hotfix for the screen updating issue involving the Unprotect method did not help.

 


Comment by: Jan Karel Pieterse (2/11/2010 5:43:39 AM)

Hi Brian,

That is an annoying bug indeed. I would not know a work-around, apart from not using the xls file format. SO if there is no real reason to keep the file in 2003 format, just upgrade the file to 2007 format.

 


Comment by: Tighe Thomas (8/12/2010 9:33:49 AM)

I am trying to create a macro in Excel 2007 that creates a Form Control check box in it. I have everything the way I want it, the only problem is when I apply the macro to certain worksheets the number of the checkbox created is always different, causing me to get the error message "identifier under cursor not recognized", refering to:

ActiveSheet.Shapes("Check Box 88").Select


Is there a way I can have the check box created always be the same number so my macro runs on every spreadsheet I need it to without having to go into VBA and manually changing the number of the check box to the number created by the macro?

 


Comment by: Jan Karel Pieterse (8/16/2010 4:37:50 AM)

Hi Tighe,

You should add some code to the macro that creates the checkbox, which gives the checkbox a different name:
Sub Foo()
    With ActiveSheet.CheckBoxes.Add(251.25, 54.75, 72, 72)
        .Name = "TEST"
    End With
End Sub


 


Comment by: Tim (1/24/2011 9:17:19 AM)

Hi JK,

Great article!

In response to the comment below, this doesn't seem to work if you want to change the actual checkbox size.
Could you be a bit more specific? Which numbers should be changed if for instace I would want to double the checkbox size in this x:Anchor range:

0, 11, 0, 7, 3, 27, 6, 8

Thanks in advance!

Tim
____________________________________________________________

Hi Laithoron,

The information is embedded in the x:Anchor attribute.
I describe the meaning of the numbers just above the "Download" heading on this page.

 


Comment by: Jan Karel Pieterse (1/24/2011 10:43:57 AM)

Hi Tim,

I expect the checkbox size itself is fixed, but I guess you'll just have to try!

 


Comment by: aM (6/20/2011 10:49:02 AM)

I have inserted a 4 check boxes (form control) in one cell in my excel spreadsheet. when i need to hide the row that the check boxes are in, they do not hide with the row - instead the stay visible in the next row overlapping with its content. how do i fix this?
your help is greatly appreciated!

Thanks in advance - aM

 


Comment by: Jan Karel Pieterse (6/21/2011 1:18:32 AM)

Hi aM,

Check out the properties of the checkboxes, set them to move and size with cells.

 


Comment by: Katrine (6/8/2012 11:12:14 AM)

This drawing1.vml file is also accessed in order to fix a bug which mirrors text in a combobox dropdown list when opening old excel files in 2010. Check out this webguide to fix it, it is great:

http://desl.co.at/php/dienstleistungen/excel2010_dropdown_mirrored.php

Deleting the "flip:y;" entry in the vml displays the text in dropdowns correctly again.

 


Comment by: Jan Karel Pieterse (6/8/2012 12:02:19 PM)

Hi Katrine,

Thanks!

 


Comment by: Scott (1/14/2013 10:20:12 PM)

Hi, I am trying to change the font size of a CheckBox control as described above but in Excel 2010. I make the changes but it has no effect. I even downloaded the example file provided above, edited as prescribed and only changed the text only from "Check Box 3" to "Yes" but it still had no effect. Is there something different in this process for 2010??? Thanks! Scott

 


Comment by: Jan Karel Pieterse (1/15/2013 11:49:06 AM)

Hi Scott,

Thanks for letting me know. The behavior has indeed changed, so I have updated this page accordingly.

 


Comment by: James (8/28/2013 5:33:42 PM)

I've managed to make it work in Excel 2010.

Along with changing the vmlDrawing1.vml file, as explained, I also found that the Drawing1.xml file also needed to be edited.

In the Drawing1.xml file, there's a bunch of attributes for the check box, and somewhere in the middle of it, you can find

<a:srgbClr val="000000"/>

Just replace the 000000 with the Hex color code (Eg, white = FFFFFF), and save and recompile along with the vml file.

 


Comment by: Jan Karel Pieterse (8/29/2013 4:16:48 PM)

Hi James,

Good find!

 


Comment by: Ebrasam (4/21/2016 10:08:04 AM)

Thanks for file:FormControls.zip !!

 


Comment by: Ebrasam (4/24/2016 10:36:26 PM)

Hi Jan,
How about combo box font size? I tried Your trick for check boxes of my file and results were great. Thanks!
But I couldn't find location of font size of combo box in vml file. Is there any solution?
Best regards!

 


Comment by: Jan Karel Pieterse (4/25/2016 12:45:40 PM)

Hi Ebrasam,

If the property isn't in the VML then there is nothing you can do, apart from using ActiveX controls.

 


Have a question, comment or suggestion? Then please use this form.

If your question is not directly related to this web page, but rather a more general "How do I do this" Excel question, then I advise you to ask your question here: www.eileenslounge.com.

Please enter your name (required):

Your e-mail address (optional but if you want me to respond it helps!; will not be shown, nor be used to send you unsolicited information):

Your request or comment:

To post VBA code in your comment, use [VB] tags, like this: [VB]Code goes here[/VB].