Open XML SDK: Character formatting in table cells with / without content

July 27, 2018

Once again, a question on Stack Overflow offered an intriguing problem that kept my brain busy for quite a while. When generating a table in a Word document cells containing no content would not retain the custom font size being assigned to each cell. Read the rest of this entry »


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 »


VBA->JS: console.log = Debug.Print

July 11, 2018

One of the most useful methods for debugging VBA is Debug.Print, to see what variables contain or what a statement returns. JavaScript has a similar capability: console.log();. Read the rest of this entry »


VBA->JS: Loading properties

July 9, 2018

The most recent post in this series introduced the concept of loading properties from the Word object before being able to work with them. The line of code in question is range.load("text"); from the Basic API snippet for Script Lab. This article goes into that concept in more depth. Read the rest of this entry »


Word Office JS APIs: Full list of font.underline types

July 8, 2018

Currently, the list of underline types in the Office JS documentation is incomplete when compared with the list offered by IntelliSense (as seen in Script Lab). Read the rest of this entry »


Copy formatted content from a Visual Studio RichTextBox to Word

June 30, 2018

One question I’ve seen fairly regularly is, “How do I copy formatted content from a Visual Studio RichTextBox to a Word document?”

The answer, of course, is, “Use the clipboard.” But behind that is another question: How to put the content in the Clipboard? Read the rest of this entry »


VBA->JS: A closer look at Script Lab and async

June 25, 2018

My previous post on getting started with Script Lab and the Office JS APIs for Word looked at some similarities between the COM and Word JS API object models, based on the Script Lab Basic API call sample. This time, I’ll highlight the core part of the sample code that differs from working with COM/VBA. 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 »


VBA->JS: A first look at the Word JS object model using Script Lab

March 28, 2018

If you’re curious about the Office JS API application object models and want to get acquainted you can do so without any investment other than time. All you need is a Microsoft account and Office 365 / Office 2016 installed on your machine (Windows or Mac) or access to Office Online. Then you can install Script Lab. Read the rest of this entry »


Office JS – APIs: State of the technology

March 23, 2018

Since last I wrote about “Web Add-ins” and the Office JavaScript API a lot has happened. Office 2016 with the updated APIs has been released and the APIs are constantly being up-dated. Those with a subscription will receive the updates more regularly than anyone who has installed Office from an msi. Web add-ins for Office 2016 (and later) run not only on the Windows desktop, like VBA, VSTO and other solutions, they also run on Mac, iPad, mobile devices and the on-line versions of the Office applications. 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 »


Provide feedback about Office to Microsoft

November 5, 2015

Microsoft has a new way to collect product feedback: UserVoice.

For as long as I can remember, it’s seldom been possible to provide feedback about Office to Microsoft. There has been the occasional conduit, hidden away, but on the whole it’s been like throwing spit balls at a brick wall…

This has changed for developers. For how long no one knows, but take advantage of it while it lasts! You can post an idea and link to it so that like-minded folks can up-vote it in order to give it more weight:

Office Developer portal

The Microsoft folks are reading and evaluating these, so take care to provide a clear, logical presentation, with example scenarios as to why the point is important.


Web Add-ins: Load, modify and insert WordOpenXML “template” file

August 27, 2015

The previous post discussed how to find out what Word Open XML is required in order to insert a particular type of content. This article will consider a practical example and demonstrate how the Word Open XML can be stored in a resource file, then loaded and modified by JavaScript code before being inserted into the Word document. Read the rest of this entry »


Web Add-ins: Using Office Open XML to extend the JavaScript APIs

August 26, 2015

In both the posts about Coercion types in Word Web Add-ins and reading built-in document properties a key point is using the Word Open XML file format in order to achieve something not available in the APIs. This approach works only in Word and it can be used for almost anything. Even the newer, extended APIs that will be released for Office 2016 won’t (initially) provide functionality for everything that can be contained in a Word document. So working with the Word Open XML file format is a useful tool for the JavaScript as well as the VBA and .NET developer. Read the rest of this entry »


Web Add-ins: Async Loops, XML in JS & asyncContext

August 14, 2015

I hope you’ve had a chance to think about the code in the previous post for reading the value of a document property. This post will consider the problem of looping when async calls are involved, using that as the basis for the discussion. Read the rest of this entry »


Web Add-ins: Reading Word Document Properties

August 13, 2015

Besides writing to a specified place in a document, the other major thing an “App for Word” can do is communicate with Custom XML Parts. Mainly, I suppose the reason this was included in the original APIs is because Word can link a content control to a node in a Custom XML Part. Changing the content of either the content control or the node will mirror that change at the other end of the link. This capability is of interest for “data-mining” documents since it’s a fairly simple task to read a Custom XML Part from a closed Word document by leveraging the Office Open XML. Read the rest of this entry »


Web Add-ins: development resources

August 10, 2015

Here’s another tool where you can try out JavaScript, on-line: JS Fiddle. The link is to the tutorial page, in the documentation. The actual editor is here.

Microsoft provides a number of resources, besides the documentation on MSDN, for learning about the Office (2013) APIs. Read the rest of this entry »


VBA->JS: Error handling (Syntax & Concept)

August 9, 2015

As is often the case with code samples, error-handling is omitted for the sake of clarity and space. But serious code requires, of course, error handling, no matter which programming language is used.

VBA is old, comparatively speaking, and classic VB, upon which it was built, even older. We’re all familiar with On Error GoTo [label], On Error Resume Next and related commands.

More recent programming languages use a different pattern, generally known as “try…catch”. The .NET Framework languages use it (although VB.NET can still work with On Error) and it’s become a widely accepted standard. This is the basic pattern in synchronous JavaScript, as well. Read the rest of this entry »


Web-Addins: Intellisense for Office APIs in Visual Studio and other tips

August 8, 2015

Here are a some tips for improving your “experience” in the Visual Studio IDE when testing the Office APIs. Read the rest of this entry »


Web Add-ins: Coercion types in Word

August 4, 2015

In the last four installments, the basics of creating a Web Add-in and reading/inserting information was introduced, using two different data formats: matrix and plain text. When working with Word, especially, formatting can be just as important as text content. For this reason, Word supports more and complexer content types than the other Office applications. This post focuses on using these coercion types in a Web Add-in. Read the rest of this entry »


Web Add-ins: Developer IDE

July 31, 2015

As you’ve seen from the discussions about JavaScript and creating the “Hello World” Web Add-in sample, working with non-proprietary programming languages, such as JavaScript, does have at least one advantage: You’re not locked into any particular software to write your code. In order to create VBA code you need the VBA editor, running in an Office application. JavaScript, HTML and CSS can be typed anywhere.

On the other hand, an editor with Intellisense and automatic formatting can save wear-and-tear on your fingers and your nerves! So this post will show you how to write Web Add-ins in a free version of Visual Studio. Read the rest of this entry »


Web Add-ins: Analyzing the “Hello World” JavaScript

July 30, 2015

I hope you’re not feeling too intimidated and have been able to create and load the “Hello World” sample

This post takes a closer look at the JavaScript part of the sample. The discussion is in two parts: First, how JavaScript is linked into the HTML page; then, the JavaScript code with the main focus on the Office JS API. Read the rest of this entry »


Web Add-in: XML Manifest & security

July 29, 2015

As became apparent in the previous post introducing Web Add-ins, a Web Add-in consists of more than a single file containing the code. Distributing and installing a Web Add-in is more complex than handing someone an Office document containing the code and explaining how to change the settings in the Trust Center so that it can run. Why is this? 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 »


Web Add-ins for (Word) VBA developers – Introduction

July 28, 2015

My discussion of Web Add-ins will center on Word, since that’s “where I live”. The information on the basics is certainly relevant to other Office applications (Excel and PowerPoint) if the Web Add-in is hosted in a Task Pane – the only kind of Web Add-in Word supports.

So, what all is involved in creating a Web Add-in? Unfortunately, it’s not only JavaScript and the Office JavaScript APIs – that’s just the programming language and object model. At least some knowledge of HTML is required and familiarity with CSS is an advantage. Read the rest of this entry »


VBA->JS: More about objects (Syntax & Concept)

July 27, 2015

So, if JavaScript is so mutable, how can the developer be sure what an object actually has in the way of properties and methods? The language provides some properties that return useful information about an object. Read the rest of this entry »


VBA->JS: Scope, objects and keeping control (Syntax & Concept)

July 26, 2015

The previous post introduced Objects in JavaScript and showed two ways to declare and populate them. This entry provides more information about what can happen to objects that a VBA developer wouldn’t expect, as well as touch on the topic of variable scope. The reason for covering both in one place is the concern for minimizing unexpected problems and maintaining control of your code. Read the rest of this entry »


VBA->JS: Object basics and unnamed functions (Syntax & Concept)

July 24, 2015

Objects as a data type were introduced in a previous post. Now it’s time to look at them in more detail. Read the rest of this entry »


VBA->JS: Named functions (Syntax & Concept)

July 23, 2015

Now that you have an idea of the basic JavaScript syntax it’s time to expand from code snippets to more complex subjects, starting with functions. This topic will extend over a number of posts as it’s not quite as simple as what we know from VBA… Read the rest of this entry »


VBA->JS: Conditionals, Loops & Operators 4 (Syntax)

July 21, 2015

In this last post on conditionals and loops I’ll present Arrays and how to loop using the last kind not yet discussed: “For Each”. Read the rest of this entry »