07-30-2013 02:27 AM
Hi,
I want to import tdms file and convert them into xlsx files. I will have many files to convert so I want to do batch processing.
I've installed the add-in, and written two VBA macros.
The first one works, but needed the user to convert file by file (with the GUI).
The second one works partially because the file is opened, but not converted...
Can someone explain me the difference between my two macros, and why the second macro doesn't convert the file ?
Thank you
Macro 1 :
Sub TDMImport()
'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.DeselectAll
Call obj.Object.Config.RootProperties.Select("Description")
'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
'Let the user choose which file to import
Dim fileName
fileName = Application.GetOpenFilename("TDM & TDMS (*.tdm;*.tdms),*.tdm;*.tdms")
If fileName = False Then
'User selected Cancel
Exit Sub
End If
'Import the selected file
Call obj.Object.ImportFile(fileName)
'Workbooks.Open (fileName)
'Record down the current workbook
Dim Workbook As Object
Set Workbook = ActiveWorkbook
Workbook.SaveAs ("C:\Documents and Settings\bzm924\My Documents\post traitement\moyenne courant de commande\04_Traces\400bar\1.xlsx")
Workbook.Close
End Sub
Macro 2 :
Sub TDMImport(fileName As String)
'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.DeselectAll
Call obj.Object.Config.RootProperties.Select("Description")
'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
'Let the user choose which file to import
'Dim fileName
'fileName = Application.GetOpenFilename(Dir)
'If fileName = False Then
' User selected Cancel
'Exit Sub
'End If
'Import the selected file
'Call obj.Object.ImportFile(fileName)
Workbooks.Open (fileName)
'Record down the current workbook
Dim Workbook As Object
Set Workbook = ActiveWorkbook
Workbook.SaveAs ("C:\Documents and Settings\bzm924\My Documents\post traitement\moyenne courant de commande\04_Traces\400bar\1.xlsx")
Workbook.Close
End Sub
07-30-2013 09:51 AM
Haven't tried it out, but could it be that
'Call obj.Object.ImportFile(fileName)
Workbooks.Open (fileName)
needs to be
Call obj.Object.ImportFile(fileName)
'Workbooks.Open (fileName)
instead?
07-30-2013 10:11 AM
In fact, the two macros are identical. I've just comment or uncomment certain parts.
If I put :
Call obj.Object.ImportFile(fileName)
In macro 1, it's Ok. But if I do it in the second one, I've got a runtime error number 5. That's why I've tried to put :
Workbooks.Open (fileName)
With a Woorkbooks.open, i'm able to open the file, but not to convert it, that's my problem.
07-30-2013 12:56 PM
I know you specifically said "in Excel" but you are in the LabVIEW forum so here is the LabVIEW solution:
http://forums.ni.com/t5/LabVIEW/Convert-Import-TDMS-to-Excel/td-p/1088746
You could build it into an EXE and then you'd be set. Optionally you could look at the LabVIEW source and you may get an understanding of what you need to do, to import it properly.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
08-01-2013 05:24 AM - edited 08-01-2013 05:25 AM
Hi,
You can find attached a working solution to my problem.
Sub ImportTDM() Call GetTDM("c:\Voltage.tdms") '### path to be adapted ### End Sub Sub GetTDM(path As String) Dim ComTDM As Object 'COMAddIn Dim TDM As Object 'ExcelTDMLib.TDMAddin Set ComTDM = Application.COMAddIns.Item("ExcelTDM.TDMAddin") ComTDM.Connect = True Set TDM = ComTDM.Object Application.ScreenUpdating = False TDM.ImportFile fileName:="" & path & "" Application.ScreenUpdating = True End Sub
The Whole discussion can be found here (in french !)
Bye
12-02-2013 04:10 AM
Hey Bro,
I m new to VBA excel and I m working on tool to prepare report based on .xlsx input. Basic need for it is converting bunch of .tdms files to .xlsx .
Can you suggest me a solution to convert bunch .tdms files at location 1 to corresponding .xlsx files at location 2.
Kindly revert back in case of any further concerns.
12-02-2013 07:42 AM
@jadhavpp2 wrote:
Hey Bro,
I m new to VBA excel and I m working on tool to prepare report based on .xlsx input. Basic need for it is converting bunch of .tdms files to .xlsx .
Can you suggest me a solution to convert bunch .tdms files at location 1 to corresponding .xlsx files at location 2.
Kindly revert back in case of any further concerns.
Once again I will link to a VI that converts from TDMS to XLSX, next time please read the entire topic.
http://forums.ni.com/t5/LabVIEW/Convert-Import-TDMS-to-Excel/m-p/1089923#M482267
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
12-02-2013 12:55 PM
12-02-2013 01:58 PM
@jadhavpp2 wrote:
Hey hooovahh
Thanks bro... But I need help in VBA excel code ...not LabVIEW...
Yeah sorry about that. But you can look at the LabVIEW code and see how it does it and then do the same code in the VBA. I do the reverse all the time because they both essentially just use ActiveX to get the meat of the work done.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord