Problème de Macro sur Excel XP et 2003
Bonjour,
j'ai un problème de Macro sur les versions XP et 2003 de Excel. Le fichier excel utilise une macro qui utilise un fichier texte sur mon c: pour compiler et calculer des données.
Je vous envoi également mon Module 1 de macro à la fin du Message!
quelqu'un pourrais m'aider à trouver mon problème puisque sur certain ordinateur la Macro fonctionne alors que sur d'autres non!
Étrange
Merci
Drix
MACRO :
Sub colismicro()
'
' COLISMICRO Macro
' Macro enregistrée le 1999/05/27 par Commission des normes du travail
'
' Touche de raccourci du clavier: Ctrl+Maj+J
'
'
'
Workbooks.OpenText Filename:="C:\COLIS dénominalisé.TXT", Origin:=1250, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True, OtherChar:="~", FieldInfo:=Array(Array(1, 1 _
), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 2), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
, 2), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 2), _
Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 2), Array(28, 1), _
Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1)), TrailingMinusNumbers:=True
Range("C1").Select
ActiveCell.FormulaR1C1 = "CENTRE " & Chr(10) & "RESPONSABILITÉ"
Range("F1").Select
ActiveCell.FormulaR1C1 = "HEURES " & Chr(10) & "SEMAINE"
Range("G1").Select
ActiveCell.FormulaR1C1 = "TAUX " & Chr(10) & "HORAIRE"
Range("H1").Select
ActiveCell.FormulaR1C1 = "ANNÉES " & Chr(10) & "SERVICE"
Range("I1").Select
ActiveCell.FormulaR1C1 = "RÉSERVE " & Chr(10) & "MALADIES"
Range("J1").Select
ActiveCell.FormulaR1C1 = "JOURS " & Chr(10) & "RÉSERVE " & Chr(10) & "MALADIE"
Range("K1").Select
ActiveCell.FormulaR1C1 = "HEURES " & Chr(10) & "RÉSERVE " & Chr(10) & "MALADIE"
Range("L1").Select
ActiveCell.FormulaR1C1 = "MINUTES " & Chr(10) & "RÉSERVE " & Chr(10) & "MALADIE"
Range("M1").Select
ActiveCell.FormulaR1C1 = "TOTAL " & Chr(10) & "HEURES " & Chr(10) & "RÉSERVE " & Chr(10) & "MALADIE"
Range("N1").Select
ActiveCell.FormulaR1C1 = "MONTANT " & Chr(10) & "RÉSERVE " & Chr(10) & "MALADIE"
Range("O1").Select
ActiveCell.FormulaR1C1 = "RÉSERVE " & Chr(10) & "VACANCES"
Range("P1").Select
ActiveCell.FormulaR1C1 = "JOURS " & Chr(10) & "RÉSERVE " & Chr(10) & "VACANCES"
Range("Q1").Select
ActiveCell.FormulaR1C1 = "HEURES " & Chr(10) & "RÉSERVE " & Chr(10) & "VACANCES"
Range("R1").Select
ActiveCell.FormulaR1C1 = "MINUTES " & Chr(10) & "RÉSERVE " & Chr(10) & "VACANCES"
Range("S1").Select
ActiveCell.FormulaR1C1 = "TOTAL " & Chr(10) & "HEURES " & Chr(10) & "RÉSERVE " & Chr(10) & "VACANCES"
Range("T1").Select
ActiveCell.FormulaR1C1 = "MONTANT " & Chr(10) & "RÉSERVE " & Chr(10) & "VACANCES"
Range("U1").Select
ActiveCell.FormulaR1C1 = "VACANCES " & Chr(10) & "ANNÉE " & Chr(10) & "COURANTE"
Range("V1").Select
ActiveCell.FormulaR1C1 = "JOURS " & Chr(10) & "ANNÉE " & Chr(10) & "COURANTE"
Range("W1").Select
ActiveCell.FormulaR1C1 = "HEURES " & Chr(10) & "ANNÉE " & Chr(10) & "COURANTE"
Range("X1").Select
ActiveCell.FormulaR1C1 = "MINUTES " & Chr(10) & "ANNÉE " & Chr(10) & "COURANTE"
Range("Y1").Select
ActiveCell.FormulaR1C1 = "TOTAL " & Chr(10) & "HEURES " & Chr(10) & "ANNÉE " & Chr(10) & "COURANTE"
Range("Z1").Select
ActiveCell.FormulaR1C1 = "MONTANT " & Chr(10) & "ANNÉE " & Chr(10) & "COURANTE"
Range("AA1").Select
ActiveCell.FormulaR1C1 = "SOLDE " & Chr(10) & "VACANCE " & Chr(10) & "FONCT."
Range("AB1").Select
ActiveCell.FormulaR1C1 = "JOURS " & Chr(10) & "VACANCE " & Chr(10) & "FONCT"
Range("AC1").Select
ActiveCell.FormulaR1C1 = "HEURES " & Chr(10) & "VACANCE " & Chr(10) & "FONCT"
Range("AD1").Select
ActiveCell.FormulaR1C1 = "MINUTES " & Chr(10) & "VACANCE " & Chr(10) & "FONCT"
Range("AE1").Select
ActiveCell.FormulaR1C1 = "TOTAL SOLDE " & Chr(10) & "VACANCE " & Chr(10) & "FONCT"
Range("AF1").Select
ActiveCell.FormulaR1C1 = "MONTANT " & Chr(10) & "VACANCE " & Chr(10) & "FONCT"
Range("M:M,S:S,Y:Y,AE:AE").Select
Selection.NumberFormat = "0.00"
Range("G:G,N:N,T:T,Z:Z,AF:AF").Select
Selection.NumberFormat = "#,##0.00 $"
Range("A:A").Select
Selection.ColumnWidth = 25
Columns("B:AF").Select
Selection.ColumnWidth = 11
Range("C:C,N:N,T:T,Z:Z,AF:AF").Select
Selection.ColumnWidth = 16
Range("B:L,O:R,U:X,AA:AD").Select
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Range( _
"B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1,O1,P1,Q1,R1,S1,T1,U1,V1,W1,X1,Y1,Z1," & _
"AA1,AB1,AC1,AD1,AE1,AF1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Range("B3").Select
ActiveWindow.SplitRow = 1
ActiveWindow.SplitColumn = 1
ActiveWindow.Panes(4).Activate
ActiveWindow.FreezePanes = True
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("A2") _
, Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Range("N3").Select
Selection.End(xlDown).Select
ActiveCell.Offset(6, 0).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.End(xlToRight).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.End(xlToRight).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.End(xlToRight).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Range("B3").Select
'
ActiveWorkbook.SaveAs Filename:="C:\COLIS dénominalisé.xls", FileFormat _
:=xlExcel5, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
End SubBonjour et bienvenue
Tu ne dis pas de quel problème il s'agit. Est-ce le fait que ce sont les formules qui sont affichées et non leur résultat ?
Je n'y connais pas grand chose en macro, mais il me semble que la tienne ne fait que mettre les titres de colonnes et les formats.
Je pencherais donc pour un problème d'options - regarde si "afficher les formules" ne serait pas coché.
Amicalement
Nad
Bonjour,
peux tu m'expliquer ou se trouve ton option ?!
voici mon Module 2 de macro au cas ou tu trouverais quelque chose :
Sub AgeEmployes()
'
' Macro1 Macro
' Macro enregistrée le 2009-05-28 par Frédéric Côté
'
'
Dim intLigneDebutRegime As Integer
Dim intLigneDebutCategorie As Integer
Dim strRegime As String
Dim strCategorie As String
Dim strCategorieCourante As String
Dim rngCourant As Range
Workbooks.OpenText Filename:="C:\70200000.DAT", Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, OtherChar:="~", FieldInfo _
:=Array(Array(1, 1), Array(2, 5), Array(3, 1), Array(4, 1), Array(5, 1)), _
TrailingMinusNumbers:=True
Range("A1").Value = "Régime" & Chr(10) & "retraite"
Range("B1").Value = "Date" & Chr(10) & "naissance"
Range("C1").Value = "Nom"
Range("E1").Value = "Catégorie"
Range("F1").Value = "Age"
Range("G1").Value = "Type" & Chr(10) & "catégorie"
Range("A1").EntireRow.HorizontalAlignment = xlCenter
Range("A1").EntireColumn.HorizontalAlignment = xlCenter
Range("B1").EntireColumn.HorizontalAlignment = xlCenter
Range("E1").EntireColumn.HorizontalAlignment = xlCenter
Range("F1").EntireColumn.HorizontalAlignment = xlCenter
ActiveSheet.UsedRange.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range _
("E2"), Order2:=xlAscending, Key3:=Range("C2"), Order3:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Range("A1").EntireRow.Insert
Range("A1").EntireRow.Insert
Range("A1").EntireRow.Insert
Range("A1").EntireRow.Insert
Range("A1").EntireRow.Insert
Range("A1").EntireRow.Insert
Range("A1").Value = "Date pour" & Chr(10) & "calcul de l'âge"
Range("A2").Value = Format(Now, "yyyy-mm-dd")
Set rngCourant = Range("A8")
rngCourant.Select
While rngCourant.Value <> ""
If rngCourant.Offset(0, 4).Value = "1" Or rngCourant.Offset(0, 4).Value = "2" Then
rngCourant.Offset(0, 6).Value = "Reg"
Else
rngCourant.Offset(0, 6).Value = "Occ"
End If
Set rngCourant = rngCourant.Offset(1, 0)
Wend
Set rngCourant = Range("A8")
rngCourant.Select
strRegime = rngCourant.Value
strCategorie = rngCourant.Offset(0, 6).Value
strCategorieCourante = ""
intLigneDebutRegime = 2
intLigneDebutCategorie = 2
While rngCourant.Value <> ""
If rngCourant.Offset(0, 6).Value <> strCategorie Then 'on change de catégorie d'emploie
rngCourant.EntireRow.Insert
'le insert se fait en haut de rngCourant
rngCourant.Offset(-1, 4).Value = "Moyenne catégorie"
rngCourant.Offset(-1, 4).Font.Bold = True
rngCourant.Offset(-1, 5).Formula = "=round(average(F" & CStr(intLigneDebutCategorie) & ":F" & CStr(rngCourant.Row - 2) & "),0)"
rngCourant.Offset(-1, 5).Font.Bold = True
intLigneDebutCategorie = rngCourant.Row
strCategorie = rngCourant.Offset(0, 6).Value
End If
If rngCourant.Value <> strRegime Then 'on change de régime
If rngCourant.Offset(-1, 0).Value <> "" Then 'pas eu de changement de catégorie, on fait la moyenne catégorie
rngCourant.EntireRow.Insert
'le insert se fait en haut de rngCourant
rngCourant.Offset(-1, 4).Value = "Moyenne catégorie"
rngCourant.Offset(-1, 4).Font.Bold = True
rngCourant.Offset(-1, 5).Formula = "=round(average(F" & CStr(intLigneDebutCategorie) & ":F" & CStr(rngCourant.Row - 2) & "),0)"
rngCourant.Offset(-1, 5).Font.Bold = True
End If
rngCourant.EntireRow.Insert
'le insert se fait en haut de rngCourant
rngCourant.Offset(-1, 4).Value = "Moyenne régime"
rngCourant.Offset(-1, 4).Font.Bold = True
rngCourant.Offset(-1, 5).Formula = "=round(average(F" & CStr(intLigneDebutRegime) & ":F" & CStr(rngCourant.Row - 3) & "),0)"
rngCourant.Offset(-1, 5).Font.Bold = True
intLigneDebutRegime = rngCourant.Row
intLigneDebutCategorie = rngCourant.Row
strRegime = rngCourant.Value
strCategorie = rngCourant.Offset(0, 6).Value
End If
rngCourant.Offset(0, 2).Value = Trim(rngCourant.Offset(0, 2).Value) & " " & Trim(rngCourant.Offset(0, 3).Value)
rngCourant.Offset(0, 5).Formula = "=DateDif(" & rngCourant.Offset(0, 1).Address(False, False) & ",$A$2,""y"")"
Set rngCourant = rngCourant.Offset(1, 0)
Wend
rngCourant.Offset(0, 4).Value = "Moyenne catégorie"
rngCourant.Offset(0, 4).Font.Bold = True
rngCourant.Offset(0, 5).Formula = "=round(average(F" & CStr(intLigneDebutCategorie) & ":F" & CStr(rngCourant.Row - 1) & "),0)"
rngCourant.Offset(0, 5).Font.Bold = True
rngCourant.Offset(1, 4).Value = "Moyenne régime"
rngCourant.Offset(1, 4).Font.Bold = True
rngCourant.Offset(1, 5).Formula = "=round(average(F" & CStr(intLigneDebutRegime) & ":F" & CStr(rngCourant.Row - 1) & "),0)"
rngCourant.Offset(1, 5).Font.Bold = True
rngCourant.Offset(0, 2).EntireColumn.ColumnWidth = 35
rngCourant.Offset(0, 4).EntireColumn.ColumnWidth = 20
Range("D:D").EntireColumn.Delete
Range("C1").Value = "Légende Catégorie"
Range("C2").Value = "1 - Temporaire (Reg)"
Range("C3").Value = "2 - Permanent (Reg)"
Range("C4").Value = "8 - Occasionnel -1 an (Occ)"
Range("C5").Value = "13 - Occasionnel +1 an (Occ)"
Range("C1:C5").HorizontalAlignment = xlCenter
Set rngCourant = Nothing
ActiveWorkbook.SaveAs Filename:="C:\AgeEmployes.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End SubRe
Je n'ai plus 2003 - De tête, dans OUTILS ==> Options
Il serait plus simple que tu joignes ton fichier.
Amicalement
Nad
Bonjour,
Vu que tu pars d'un fichier texte j'aurais tendance à penser que certaines colonnes sont au format texte.
Après l'ouverture du fichier repasse toutes tes cellules au format 'standard' avec :
Cells.NumberFormat = "General"
et vois si ça resoud ton pb.
Sinon l'option dont parlait nad c'est 'outils / options...' onglet 'affichage' : décocher 'formules'
eric