10-06-2009 12:34 PM
I was looking at the NI TDMS import plugin for Excel and it seems that the newest version of the plugin uses the COM API which could allow the import function to be used automatcially. There is a short info page about this here http://zone.ni.com/devzone/cda/tut/p/id/10207 but I'm new to Excel Macros and VBA so I'm not sure how to go from this tutorial to what I am wanting to do.
Specifically, I am wondering if anyone knows (and could post an example of) how to do the following:
From within a labview VI, the user would select a path to a tdms file. Once this path is selected, the VI would call the TDMS import excel plugin and run it on the file.
Solved! Go to Solution.
10-06-2009 01:47 PM
After playing with things, I have worked out the solution to this and I am posting it for everyone in case it can be of some use. In order to use this solution to work out of the box, you will need the report generation toolkit. If you don't have that, you would need some other way of launching Excel from labview and running a macro. Hopefully someone who has the knowledge on how to do that will post that portion in this thread for those who don't have the toolkit
To start out, open excel and in the menubar select Tools -> Macros -> Visual Basic Editor. The source for the macro you will create is:
Sub TDMImport(fileName)
'Get TDM Excel Add-In
Dim obj As COMAddIn
Set obj = Application.COMAddIns.Item("ExcelTDM.TDMAddin")
obj.Connect = True
'Confirm only importing "Description" properties for Root
Call obj.Object.Config.RootProperties.SelectAll
'Show the group count as property
Call obj.Object.Config.RootProperties.Select("Groups")
'Select all the available properties for Group
Call obj.Object.Config.GroupProperties.SelectAll
'Import custom properties
obj.Object.Config.RootProperties.SelectCustomProperties = True
obj.Object.Config.GroupProperties.SelectCustomProperties = True
obj.Object.Config.ChannelProperties.SelectCustomProperties = True
'Import the selected file
Call obj.Object.ImportFile(fileName, False)
'Record down the current workbook
Dim Workbook As Object
Set Workbook = ActiveWorkbook
End Sub
Once you have copied/pasted this into the editor go to the menubar and hit File -> Export File and save the macro as a .BAS file
You will also need to go to Tools -> Macros-> Security and select the Trust Visual Basic Project option in order for the macro to be called from LV.
Once all this is done, you can use the attached VI (Saved in LV 8.6) Simply supply the path to the BAS file and the TDMS file via the front panel controls and click run and the TDMS import will happen automatically.
09-21-2011 08:55 AM
I am interested in completing the same task, however I don't have the report generation toolkit. I have installed the free excel toolkit found on the fourms and was wondering if someone could help me with this task using the free toolkit.
Thanks,
Alex
09-21-2011 04:13 PM
I don't have any experience with the free toolkit but if it has a way of calling a macro it should be possible to do without too much trouble. Essentially what you need to do is call the Excel macro I posted with the filename you want to load as a parameter.
If that doesn't pan out with the free toolkit, you could see if there is a way to run an excel macro from the system command line then use the system exec VI to do that from within LabVIEW. Here is something I found on StackOverflow that may help you if you need to go this route:
http://stackoverflow.com/questions/2050505/way-to-run-excel-macros-from-command-line-or-batch-file
09-22-2011 07:02 AM
Thanks for the response. I do have a Run Macro.vi, however, the part I am stuck on is the "Excel Import Module.vi". Can you explain what this .vi does so I can find a replacement method.
Thanks,
Alex
09-22-2011 07:38 AM
Basically what the module you are asking about does is import a macro contained in an external (.bas) file into the excel workbook. You don't necessarily have to do this though. If I recall correctly, there is a way you can add user macros into excel that can be called for any workbook.
Another possibility would be if the free toolkit has a 'create macro' type VI which you could then load with my macro and run.
09-22-2011 02:47 PM
You are correct. There is a way to have a Macro be used in any workbook. I was able to get it to work. Thanks