AppleScript Tutorial for Excel
The AppleScript products are designed for Mac users that use Excel for Mac 2004 and 2008. Later versions should use VBA Macros which are cross-platform compatible with Windows and Mac for Excel versions 2011 and up including local installations of Office 365.
AppleScript Tutorial for Excel using Universal Fonts
When data needs to be encoded in a barcode, the script will format the data and return a character string that will create an accurate barcode when combined with the appropriate Universal Font. As a reference, two files included in the Universal Barcode Font Package, AppleScript_Excel_Example.xls and the AppleScript_Excel_Example_IDAutomation128b.scpt file can be used as a guide. Available in the licensed version only.
- Open the Excel Example or a new Excel spreadsheet.
- In Column A, enter test data for rows A1, A2, and A3. In the example, rows 1 through 3 of Column A already contain data.
- Save the Excel file.
- Open the AppleScript Editor and spreadsheet that will be used. (Ex: AppleScript_Excel_Example.xls)
- Paste the code below into the AppleScript file. If the sample script file is being used, the code has already been placed in the script. Make sure that only one Excel worksheet is running.
NOTE: AppleScript_Excel_Example.xls is a working example using the following code. When using a different spreadsheet, the code will need to be modified to match the column and row setup.
--Run handler showing communication with Excel on run
tell application "Microsoft Excel"
tell sheet "Sheet1" of workbook 1
set EndofRow to 3 -- This defines the last Excel Row with data; it this example, it is A3.
set input_data to ""
repeat with i from 1 to EndofRow -- This loop will run from row 1 until EndofRow set above. For this example, it was set to 3.
set InputCell to the value of (cell i of range ("A1:A" & i)) -- This line defines the range, where in this example it is set A1:A3 and i is the counter and will continue to loop until EndofRow.
set input_data to InputCell
set encoded_data to IDAutomation_Uni_C128b(input_data) of me
set EncodedCell to ("B" & i) -- This is where to designate where the encoded data is to appear. In this example, the encoded data will be in Column "B".
set value of cell EncodedCell to encoded_data
--End of Excel Code
- Save the changes, then compile and run the script. The Excel spreadsheet now contains encoded data in cells B1 through B3 on the example spreadsheet. set EncodedCell to ("B" & i) ensures that the encoded data is sent from the script directly to Column B. To send the data to another column, simply enter the Column letter.
- Change the font of the formula field to the IDAutomation Universal Font and set the point size. This is a very important step; if this is not done, barcodes will not be displayed. If unsure of the point size, IDAutomation recommends 12 points.
- Print and scan the barcode(s) to verify the correct data are encoded.