Web Add-ins (Word): Tabs and Tabstops – extending the API using OOXML

July 14, 2018

A few days ago I encountered a question on Stack Overflow about using tabs to align content in a Word document. The required result was something like this:

I started looking at the Word JS API documentation and realized there is nothing in that object model for inserting tabs or defining tab stops. Read the rest of this entry »


Removing a ListTemplate from a style in Word

March 29, 2018

Ran into an interesting question on Stack Overflow the other day. The problem description is short, so I’ll copy it here:

There is a word VBA method style("style").LinkToListTemplate ListTemplate:=Nothing which is used to set the style numbering to None. My problem is that I cannot find the same in C# word interop. The method exists but does not work with style.LinkToListTemplate(null).

Read the rest of this entry »


If your VSTO solution crashes after running for a while…

February 23, 2018

…and the problem isn’t reproducible.

I was confronted with a request to trouble-shoot such a situation, not long ago. A large organization contacted me and this was the problem description. Read the rest of this entry »


Bug Word 2013: COM exception comparing documents

July 29, 2015

I’m breaking the rhythm of the series on Web Add-ins to report a bug that was discovered by a developer in the VSTO forum, this week. Read the rest of this entry »


BUG Word 2013: Selection in Word disappears after running code

February 26, 2014

Since the release of Word 2013 we’ve been seeing sporadic complaints in the Word forum from developers that the selection highlighting disappears after their code executes. Only yesterday did someone post steps to reproduce the issue that worked consistently.

It turns out that this is, indeed, “unexpected behavior”. Apparently the screen redraw isn’t firing as it should.

There is a workaround, although it’s not ideal as it causes some screen flicker:

The Application.ScreenRefresh method will make the selection highlighting visible, again.

Changing the zoom factor should also work.


Word: Difficulty processing fields in the footer during printing

February 7, 2014

Once again, a forum discussion has brought to light something new and useful to know when working professionally with Word.

When someone asks how to display different content in the footer for the last page, only, the recommended approach since time immemorial is to use an IF field. The If field tests whether the current page number is also the last page number. When that’s the case, different content is displayed. Basic instructions on how to set this up can be found on the Word MVPs FAQ site. It’s not always simple to set up, but it works.

Except in this case, it didn’t… Read the rest of this entry »


Problem using a URL as index for the Documents collection

September 3, 2013

A poster in the Word for Developers forum has brought a new problem with the Documents collection to light this week. Unlike the one discussed in an earlier blog post, this behavior applies to all current versions of Word, including 2013.

Back when the Internet was comparatively new, Word didn’t know how to handle URLs as paths to files at all. The Open and Save methods of the Document(s) object couldn’t deal with anything that wasn’t a standard local or network path. At some point, this was rectified and Word can quite happily open and save documents to Internet, SharePoint and Skydrive sites.

What Word still can’t handle, however, is a URL as the index value to identify a Document object in the Documents collection. Code such as the following triggers the error 4160 “Bad file name”. Read the rest of this entry »


Trapping events on a repeating section content control

August 21, 2013

[This is the follow-up to a previous post about mapping repeating content controls to a custom XML part.]
As a developer, you might want to be notified when the user adds a new set of mapped nodes to a repeating section, or deletes a set. If you look for events for Content Controls to help you with this you won’t find any.

Nor are there any events at the document or application level.

And you can’t re-purpose the entries placed in the context menu for adding or removing a repeating section item.
RepSec4

So, what can you do? Read the rest of this entry »


Repeating section content control in Word 2013

August 20, 2013

Some significant improvements were made to Word’s content controls in Word 2013. You can find an overview here.

One interesting capability is a new kind of content control that brings back some of the functionality lost when XML nodes technology had to be pulled from Word due to the court decision in 2009. In the original release of Word 2007, xml nodes inserted into a table could be configured to repeat automatically when new table rows were inserted. While content controls in Word 2007 and 2010 can take over a lot of what could be done with xml nodes, this – and validation – were not possible “out of the box”.

A large portion of the article linked to above covers the new type of content control, in the section “Supporting repeating content”. You’ll also find a practical introduction, mainly targeting the “power user” on Greg Maxey’s site.

Something that doesn’t really jump out at you in any of the information I’ve found so far is how to

  1. Map a repeating section to a list of data already present in a Custom XML Part so that it all displays in the document
  2. Trap when the user adds or deletes a new data item (the repeating section must be mapped to a Custom XML Part in order for this to work)

Read the rest of this entry »


Word 2013: Missing object model documentation

May 2, 2013

I think many of us are still trying to come to terms with the fact that the only Help for Office 2013 is on-line. The official information can be found here:
http://technet.microsoft.com/en-us/library/cc178954.aspx
in the section AWS (Assistance and Worldwide Services).

The official line is that this is “better” all around. Help can now be searched on-line and translated. Of course, the fact that this was already the case for almost ten years isn’t mentioned…

Truth be told, the real reason is resources (financial). If Help has to be delivered with the product, then it has to be written before the product is released. This means lots of man-hours just prior to release, then down-time until the next product release. So, to a certain degree, the decision is understandable.

The other side of the coin, however, is that there’s no deadline that forces the documentation to actually be done and finished.

The result at the time of this writing, some months after the official release of Office 2013, is that the object model language reference (Help) hasn’t been reviewed for relevance to Office 2013, and new functionality isn’t fully incorporated. So you can spend literally hours trying to find information in the new, less friendly MSDN interface with the result that
you can’t find what you were looking for because it’s simply not there.

The “final straw” for me was a question about the Word object model in the Word for Developers forum the other day. So I’ve set up a new “page” on this blog to document un-documented behavior and information concerning Office. Everyone is welcome to contribute!


Word 2013: AutoSave and the new property IsInAutoSave

March 17, 2013

In a previous post I wrote about a change in Word’s behavior: Even if the user chooses “Don’t save” when closing a Word document, the DocumentBeforeSave event triggers.

We’ve been thinking this is a bug, but it turns out that it’s not – it’s by design. Read the rest of this entry »


Word 2013 Bug: “Not available for reading” error on opening a document

February 22, 2013

The more people use Word 2013, the more changes and problems are bubbling to the surface. Again, this one was brought to the world’s attention in the Word for Developers forum.

“Reading mode” was introduced a few years ago to provide a more efficient way to read documents on-screen. By default, documents opened from an e-mail attachment will display in this view. As the view is optimized for reading, most editing commands are not available while in that mode. This lock-out also applies to the object model. When code tries to make modifications to the document that aren’t allowed while in reading mode, you see run-time error 4605: “This method or property is not available because this command is not available for reading”. Read the rest of this entry »


Word 2013 Bug: DocumentBeforeSave event triggering when user chooses “Don’t save”

February 20, 2013

EDIT: There’s an update to this in a new blog entry. To summarize: this behavior is by design and there is a workaround for the problem.

A new bug was reported in the Word for Developers forum this week. I also received an email about the same behavior. Microsoft confirms the behavior but isn’t yet ready to call it a bug. I call it a bug.

To summarize: In all versions of Word through 2010, when you are monitoring the DocumentBeforeSave event the event only triggers if the user chooses to Save the document. If the user chooses not to save when the prompt appears, the event does not trigger.

In Word 2013 the event also triggers when the user chooses “Don’t save”.


Word 2013: Templates location and File/New

February 6, 2013

When you create a new document in Word, it automatically bases on a template. By default, this will be the built-in Normal.dotm, but it can be any *.dotx or *.dotm file. This document will maintain a link back to the template, enabling it to use Building Blocks, Ribbon customization and macros in the template.

Users and companies provide templates for specific, oft-occurring tasks. In order to make them easily discoverable, they should appear in the interface presented for creating a new document. With the exception of Word 2007, that had an “Office button” rather than a File menu, this interface is accessed via the command File/New.

Up until the introduction of the Backstage in Office 2010, this interface was the File New dialog box. In Office 2010 and 2013, it’s a Backstage view, but in Word 2010 you have to click the link “My templates” in order to access custom templates, which are still offered in the File New dialog box. In Word 2013, custom templates are listed in the Backstage view in the “Personal” list (below), but not necessarily all of them. Why this is, is the topic of this post. Read the rest of this entry »


Bug Word 2010/2013 with Enumeration wdFindAsk

January 3, 2013

As more people migrate away from Word 2003 and 2007 to a newer version, more bugs are starting to come out of the woodwork. Again, this one was brought up in a forum.

When a developer writes code to use Word’s built-in Find functionality, it’s usually to do a “Replace all”, or to run a loop that stops after every “hit” until the entire search Range has been processed. It’s therefore common practice to pass wdFindStop to the Wrap property (or argument of the Execute method).

It’s only rarely that we see code using wdFindAsk, so perhaps it’s not surprising that the bug hadn’t been reported previously by earlier adapters of Word 2010…

In the problem scenario, Find should only run on the current selection, then ask the user whether it should continue to execute across the entire document. This is quite legitimate and imitates the user interface. What’s happening is that Find does not stop after checking the current selection, but continues to run for the entire document (does the same as wdFindContinue).

Interestingly enough, wdFindAsk does work correctly when the end of the document is reached, asking the user if the search should continue from the beginning of the document.

Following is some VBA code that works around the problem, so that the user is queried both at the end of the selection and at the end of the document. Read the rest of this entry »


Bug Word 2010: Documents collection is not correctly maintained

November 9, 2012

A person in the Word for Developers forum brought an important bug to our attention last week. When documents are opened/created then closed the Documents collection does not keep proper track. The index value is not reduced correctly (there are more documents in the collection than there should be) and some document names are missing while others are duplicated. (The thread with repro code sample can be found here.) Read the rest of this entry »


Word 2013 WordOpenXML incomplete: missing Comments extensions

October 20, 2012

In the initial release of Word 2013 the new Comment extensions, contained in the commentsEx.xml part, are not written to the XML returned to the object model property Range.WordOpenXML. Read the rest of this entry »


How the Backstage affects repurposing using Word 2013 VBA

October 1, 2012

New month, new topic – for the moment, at least. Forums are such a wonderful source of topics to write about… Today’s comes from a question in the Office 2013 Preview for Developers forum on MSDN.

In Word 2010 the Backstage was introduced with the purpose of providing management functionality for Office documents. The Backstage provides a large, for the developer customizable surface to interact with the user. Another reason for this move was to provide the same “experience” for the users of all the Office applications when using basic file management functionality.

As always, when something is “harmonized”, individuality is lost. We’ve experienced that since the first attempts at giving the Office applications a unified interface and the trend continues. Read the rest of this entry »


Word 2013 Comments in the Object Model

September 26, 2012

In my last post I presented some of the new Comment functionality in the Word UI. The new functionality for Comments is also reflected in Word’s object model. Read the rest of this entry »


Collapsing Outline levels in the Word 2013 object model

September 6, 2012

In my last blog post I described the new functionality in the Word 2013 UI for collapsing and expanding Headings and Outline levels. Today, I’ll cover the corresponding additions to the Word object model. Read the rest of this entry »