LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TDMS to XLSX in Excel

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

0 Kudos
Message 1 of 9
(6,005 Views)

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?

0 Kudos
Message 2 of 9
(5,982 Views)

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.

0 Kudos
Message 3 of 9
(5,978 Views)

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.

0 Kudos
Message 4 of 9
(5,967 Views)

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

0 Kudos
Message 5 of 9
(5,934 Views)

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.

0 Kudos
Message 6 of 9
(5,755 Views)

@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

0 Kudos
Message 7 of 9
(5,746 Views)
Hey hooovahh

Thanks bro... But I need help in VBA excel code ...not LabVIEW...
0 Kudos
Message 8 of 9
(5,734 Views)

@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.

0 Kudos
Message 9 of 9
(5,717 Views)