Page 1 of 1

Reading and writing to and from Excel

Posted: Wed 29. Mar 2017, 08:49
by spatel
Hello,

i am new to PCAN Explorer and wanted a help regarding reading and writing function of VBScript Macros.

a signal is assigned to a vertical slider and i want to read value from a excel file (*.xlsx) and provide that value to that signal.

i got to know from help that it is possible to read and write Values using an .txt file. But i want to open an excel file (*.xlsx) using a macro and read a range of Values from a specific sheet (from a set of 8 sheets workbook), from a specific cell range (e.g. "A15 to A20"), and assign it to my signals one by one.

Similarly write a value obtained from another Signal to the same sheet but at different cell name (e.g. "E21").

is it possible to do so?
P.S. i am using a Button as a trigger to execute the Macro command

Thank you in advance.

Re: Reading and writing to and from Excel

Posted: Wed 29. Mar 2017, 15:27
by PEAK-Support
This have nothing to do with PCAN-Explorer. Reading Data from a Excel Sheet in VBS is a Microsoft related problem.

here a simple code snip how to create a Excel connection:

Code: Select all

PrintToOutputWindow "create Excel connection"  
 Set objXL = CreateObject("Excel.Application") 
 objXL.Visible = True ' make it visible...also possible to bring to top
 Set wbXL = objXL.Workbooks.Add()' ' New sheet
 Set sXL = wbXL.Worksheets(1) ' goto Sheet1 

 ' write Header
 sXL.Cells(1,1) = "PEAK-System Technik PCAN-Explorer5 VBS Excel Demo (c)2013 PEAK Darmstadt"
 sXL.Cells(3,1) = "No."
 sXL.Cells(3,2) = "Voltage"
 sXL.Cells(3,3) = "Current"
 sXL.Cells(3,4) = "Power"
This sample code create a new sheet and write to some cells - you also could open a existing sheet and read from cells.