July 17, 2019

How to use TWAPI in a Surpac macro to read directly from a spreadsheet

  Using CSV or text files are a great way to give…
Avatar Trevor Lukaniuk

Using CSV or text files are a great way to give input or instructions to TCL macros in Surpac, however, it’s often a hassle to work in the CSV format. Not only will you have to worry about maintaining two versions of the same data (.xlsx and .csv), saving the Excel sheet into CSV will lose its formulas, references and formatting. You also have to save, taking the steps to save-as a CSV every time you make an update to the spreadsheet.

To get around these inconveniences, lately I have been using TWAPI in my Surpac macros, to interface directly with Excel, and I would like to show you how.

STEP 1: I will first assign variables for the name of the excel file, as well as the range of cells you want to read from the spreadsheet.

TWAPI will need the absolute path of this file, but for simplicity’s sake in inputs, I usually just give the relative path from the working directory.

Stay up to date

Receive monthly updates on content you won’t want to miss


Register here to receive a monthly update on our newest content.