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
|
Public appExcel As Excel.Application 'Application Excel
Public wbExcel As Excel.Workbook 'Classeur Excel
Public wsExcel As Excel.Worksheet 'Feuille Excel
Private Sub Visu_fichier_Click()
fichier = Mid(fichier_VIDAGE, 1, Len(fichier_VIDAGE) - 4)
fichier = fichier & ".txt"
Name fichier_VIDAGE As fichier
fichiersave = App.Path + "\" + adresse_expl + ".AH" + "\" + fichier
Set appExcel = CreateObject("Excel.Application")
If Option1.Value = True Then
Workbooks.OpenText filename:=fichiersave, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, Comma:=True
Else
Workbooks.OpenText filename:=fichiersave, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, Semicolon:=True
End If
Set wbExcel = appExcel.ActiveWorkbook
appExcel.Visible = True
Call EcrireDansThisWorkbook
end sub
Sub EcrireDansThisWorkbook()
Dim i, NomFich, x As Long
NomFich = ActiveWorkbook.Name
wbExcel = ThisWorkbook.Name 'j'ai une erreur à ce moment là
For i = 1 To Application.VBE.VBProjects.Count
If InStr(Application.VBE.VBProjects(i).filename, NomFich) <> 0 Then
For Each LeModule In Application.VBE.VBProjects(i).VBComponents
If LeModule.Name = "ThisWorkbook" Then
x = LeModule.CodeModule.CountOfLines
LeModule.CodeModule.InsertLines x + 1, "Private Sub Workbook_BeforeClose(Cancel As Boolean)"
LeModule.CodeModule.InsertLines x + 2, " Application.Run """ & ClasseurPrincipal & "!Tempo"""
LeModule.CodeModule.InsertLines x + 3, "End sub"
End If
Next
End If
Next i
End Sub |
Partager