Here are a some tips for improving your “experience” in the Visual Studio IDE when testing the Office APIs.

Intellisense
As mentioned in the discussions about declaring variables and working with data types, JavaScript does not strongly type variables – it’s a bit like declaring everything as Variant in VBA. One consequence of this is that, when you pass a variable as a parameter to a function you lose Intellisense: JavaScript doesn’t retain what it “knew” about the variable in the calling procedure.

Here’s a trick for assigning the data type to a parameter. Note carefully how these instructions are written, JavaScript is not generous in ignoring typos! These instructions must be at the very beginning of the function, before any other lines of code.

function InsertAndFormat(ctx, rng, text, bold, italic) {
    ///  
    /// 
    /// 

You can find more information here.

Making selections in Visual Studio
Those of us who’ve used Word since the early days have often made use of Word’s ability to allow a rectangular selection anywhere on the page. When Microsoft introduced the Research task pane, back in version 2007, and assigned it to the Alt + click combination it became difficult (almost impossible) to use, so perhaps not everyone remembers it.

But apparently someone on the developer team for Visual Studio did, because the exact same capability is available in the VS code editor. Just hold down Alt and start dragging…

Editing while in debug mode
VBA developers are accustomed to being able to edit code while debugging / stepping through and seeing the results. Visual Studio – running outside of the Office applicatoin process – can’t provide the same level of comfort. Especially irritating is having to stop debug mode in order to make a change, then starting over again.

It’s possible to at least not have to leave debug mode in order to test changes you make to your code during debugging. The trick is to add a link to the HTML page in the task pane window that will update the underlying code when clicked:

  1. Open home.html.
  2. Decide where you’d like to have this useful hyperlink and enter the following (the text between the <a> tags can be anything you want):

    <a href="location.reload(true)">Refresh add-in</a>

  3. Save home.html.

Now, when you do any editing to the code, remember to SAVE your changes, wait for VS to finish doing so, then click the link to refresh the add-in in the task-pane.

Leave a Reply