Bonjour,
Je veux convertir des fichiers tdms (Labview) en fichiers Excel.
Je vais avoir beaucoup de fichiers a convertir, donc je veux faire une macro pour automatiser le processus.
Pour pouvoir décrypter les fichiers, il faut utiliser l'add-on disponible ici :
http://zone.ni.com/devzone/cda/epd/p/id/2944
Et il y a un exemple de macro d'utilisation là :
http://www.ni.com/white-paper/10207/en
La macro proposée (macro 1) marche parfaitement. Mais elle demande d'ouvrir les fichiers un par un. J'ai essayé d'automatiser le processus, mais je ne parviens pas à mes fins.
Si je mets un :
j'ai une erreur runtime 5.
Code : Sélectionner tout - Visualiser dans une fenêtre à part Call obj.Object.ImportFile(fileName)
Si je mets un :
Le fichier s'ouvre bien mais n'est pas converti, il n'est donc pas lisible.
Code : Sélectionner tout - Visualiser dans une fenêtre à part Workbooks.Open (fileName)
Je cherche donc comment combiner la conversion du fichier grâce à l'add-in, et l'ouverture automatique des fichiers.
Merci
Macro 1 :
Macro 2 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 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
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 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
Partager