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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| Sub Importation()
Dim Wb As Workbook
Set Wb = ThisWorkbook
For k = 1 To 2
'Get TDM Excel Add-In
Dim obj As COMAddIn
Set obj = Application.COMAddIns.Item("ExcelTDM.TDMAddin")
'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 (seulement pour k=1)
If k = 1 Then
Dim fileName
fileName = Application.GetOpenFilename("TDM & TDMS (*.tdm;*.tdms),*.tdm;*.tdms")
If fileName = False Then
' User selected Cancel
Exit Sub
End If
chemin = Left(fileName, InStrRev(fileName, "\"))
End If
'Import the selected file
Call obj.Object.ImportFile(fileName, False)
'Supprimer la feuille et ligne inutiles et renommer la feuille 1 + enregistrer futur nom du classeur final
Dim NomFichier As String
Application.DisplayAlerts = False
If NomFichier = "" Then
NomFichier = Left(Worksheets(1).Cells(2, 1), InStrRev(Worksheets(1).Cells(2, 1), ".") - 1)
End If
Worksheets(1).Delete
Range("A1").EntireRow.Delete
Worksheets(1).Name = "Feuil" & k
'Record down the current workbook
ActiveWorkbook.SaveAs fileName:="Données" & k, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.DisplayAlerts = True
'Process the imported data
'...
Next
Dim Wbd1 As Workbook
Dim Wbd2 As Workbook
Set Wbd1 = Workbooks("Données1.xlsm")
Set Wbd2 = Workbooks("Données2.xlsm")
Wbd2.Worksheets("Feuil2").Copy After:=Wbd1.Worksheets("Feuil1")
Wbd2.Close SaveChanges:=False
Wbd1.SaveAs fileName:=NomFichier, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Wbd1.Close SaveChanges:=False
Dim chemin_1 As String, chemin_2 As String
chemin_1 = chemin & "Données1.xlsm"
chemin_2 = chemin & "Données2.xlsm"
Kill chemin_1
Kill chemin_2
Wb.Close SaveChanges:=False
End Sub |
Partager