Example Code

Excel and LabVIEW in multi-user environment

Code and Documents

Attachment

There are plenty examples on the web and shipped with LabVIEW on how to use Excel. But once you start developing more or less complicated applications you start dealing with sharing Excel instances with other Users, programs and within the application itself.

Below I would like to share my solution to Excel sharing in multi-user environment.

In future it would be really nice if: native LabVIEW Automation Open OpenAutomation.pngallows us to request instance by name or ID, not just new or unknown instance.

Built-in Excel features used:

  • IgnoreRemoteRequests (disables DDE interface, COM call's still need to be tracked or kept in mind) - to reserve given Excel instance for LabVIEW only
  • DisplayAlerts - to leave error checking to LabVIEW only
  • UserName - for identification in LabVIEW environment
  • AutoRecover -> Enable - for house cleaning purposes

Concept:

A storage VI with 7 modes:

Mode/CommandDescriptionUsage
List AllLists all active (obtained by this vi) Excel instancesnormal(default)
Open New InstanceOpens new instance of Excel Applicationnormal
Get Instance by NameGets active LabVIEW's Excel App. RefNumnormal
Close Instance by NameCloses active instance by Namenormal
Close instance by RefNumCloses active instance by RefNumnormal
Kill AllKill's all active Excel instances (global process kill command)house cleaning
Close AllCloses all active LabVIEW"s Excel instancesnormal

Excel Automation Control.png

Simple Example provided.

04/26/2011 Update:

  • minor facelift
  • "List All" command added

04/27/2011 Update:

  • On Exit Excel must be returned to DDE listen state, otherwise it would ignore requests from OS to open documents (Directly still would work)
  • Check on instance name collision
  • Additional error checking

05/02/2011 Update:

Bug found in Close by RefNum.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors