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 »


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 »


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 »


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 »


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

July 20, 2015

In the third part of working with conditionals we’re going to look at some looping operations. Again, the concept is the same as what’s used in VBA, just different syntax. Read the rest of this entry »


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

July 19, 2015

Now that you’ve familiarized yourself with the logical operators JavaScript uses it’s time to look at the basic conditional constructs. Looping constructs are the topic of the next post. Read the rest of this entry »


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

July 19, 2015

An important part of most programs we write is testing the values of variables and performing tasks based on the result. Typical VBA constructs that use comparisons are If, For, ForEach and Do…While. JavaScript provides the same functionality, using pretty much the same logic, but the syntax differs.

Before we look at these in the next post, however, it’s first important to learn what operator symbols JavaScript uses, how code blocks are defined and to understand the way the Equal sign ( = ) works. Read the rest of this entry »


VBA->JS: Case sensitivity (Syntax)

July 17, 2015

When working in VBA it doesn’t matter, for the most part, whether you type capital or small letters. VBA will monitor and compare with its internal list of keywords as well as variables you’ve declared and make corrections as you go. If there are variables that aren’t declared there are no automatic corrections, but VBA doesn’t care. On the whole, you only have to be careful when typing Style names and Find expressions when “Match Case” is in-force. Read the rest of this entry »


VBA->JS: String concatenation (Syntax)

July 16, 2015

The VB languages differentiate between concatenating (“adding”) strings and adding numbers. You’re supposed to use an ampersand (&) to concatenate a string and a plus sign (+) to add numbers. Although VBA will accept a plus sign to concatenate strings it’s frowned on as you can get unexpected results.

JavaScript (like C#) must use the same operator for both operations, the plus sign: Read the rest of this entry »


VBA->JS: Comments (Syntax)

July 16, 2015

Commenting code is important. JavaScript and C# use the same commenting conventions, which differ somewhat from VBA’s. Comments can be on a single line, similar to VBA; they can also extend across multiple lines: Read the rest of this entry »