bonjour, j'ai un problème dans mon code mais ne comprend pas pourquoi. Je lis un fichier texte et grace aux valeurs de celui-ci j'ouvre un fichier excel.
Cependant a un moment donnée VBS plante. Il m'ouvre bien les fichiers voulu. Le code fonctionne lorsqu'on ne rentre pas dans le 2eme IF .
Voici mon code
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
fichier="Y:\Univers\VBO\test.txt"
 
Const ForReading = 1, ForWriting = 2 
Dim oFso, f
Dim variable
 
  Set oFso = CreateObject("Scripting.FileSystemObject")
  Set f = oFso.OpenTextFile(fichier, ForReading)
  dateHier="27/06/2011"'DateAdd("d",-1,date())
  while Not f.AtEndOfStream
  	variable=f.ReadLine
  	If Mid(variable,1,1)="v" Then 
  		datedeb=Mid(variable,12,2) &"/"& Mid(variable,10,2) & "/" &Mid(variable,6,4)
  		datefin=Mid(variable,21,2) &"/"& Mid(variable,19,2) & "/" &Mid(variable,15,4)
  		If DateDiff("d",Datedeb,Date())>0 and DateDiff("d",Date(),datefin)>0 Then
	  		dir_camp=RTrim(Mid(variable,32,20))
	  		titre_camp=RTrim(Mid(variable,60,50))
	  		repertoire_de_diffusion = "\\societe.mma.fr\mmaracine\SAS1\GC\Campagnes\" & dir_camp & "\preparation\1 - Inscriptions a l operation\Diffusion"
	  		Set objExcel = CreateObject("Excel.Application")
				Set wbExcel = objExcel.Workbooks.Open (repertoire_de_diffusion & "\Validation" & titre_camp &" au " & year(dateHier) & "_" & Right("0" & month(dateHier),2) & "_" & Right("0" & day(dateHier),2) & ".xls") 
				objExcel.visible = true
				objExcel.DisplayAlerts = true
				wbExcel.Save
				objExcel.DisplayAlerts = True 
				objExcel.Application.Quit
				'Mise en lecture seule des fichiers
	  		MonFichier = repertoire_de_diffusion & "\Validation" & titre_camp &" au " & year(dateHier) & "_" & Right("0" & month(dateHier),2) & "_" & Right("0" & day(dateHier),2) & ".xls"
	  		Set oFSO = CreateObject("Scripting.FileSystemObject")
	  		Set f = oFSO.GetFile(MonFichier)
	  		f.attributes = f.Attributes OR 1
  	End if
 
  	End If
  Wend
  f.Close
  MsgBox "FIN"