Erreur sur hasTitle Excel vba
Bonjour à tous,
j'essaie de créer un grpahique à partir de données que j'ai exporté sur Excel.
Cela me met une erreur 1004 sur le hastitle.
Je suis dessus depuis hier soir.
Merci pour votre aide
voici mon code
Code:
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
| Dim xlApp As Excel.Application
Dim xlWrkbk As Excel.Workbook
Dim xlChartObj As Excel.Chart
Dim xlSourceRange As Excel.Range
Dim xlColPoint As Excel.Point
On Error GoTo Err_CreateChart
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, _
"dossierParFisc_AC", CurrentProject.Path & "\test1.xls", False
Set xlApp = CreateObject("Excel.Application")
Set xlWrkbk = xlApp.Workbooks.Open(CurrentProject.Path & "\test1.xls")
Set xlSourceRange = _
xlWrkbk.Worksheets(1).Range("a1").CurrentRegion
Set xlChartObj = xlApp.Charts.Add
With xlChartObj
.ChartType = xl3DColumn
.SetSourceData Source:=xlSourceRange, _
PlotBy:=xlColumns
.Location Where:=xlLocationAsNewSheet
ActiveChart.HasTitle = True
With .ChartTitle
.Characters.Text = _
"ANNEE"
.Font.Size = 18
End With
.Axes(xlCategory).TickLabels.Orientation = 45
.Axes(xlSeries).Delete
.HasLegend = False
' with no decimals.
With .SeriesCollection(1)
.ApplyDataLabels Type:=xlDataLabelsShowValue
.DataLabels.NumberFormat = "$#,##0"
End With
End With
' Position the points further from the tops
' of the columns.
For Each xlColPoint In _
xlChartObj.SeriesCollection(1).Points
xlColPoint.DataLabel.Top = _
xlColPoint.DataLabel.Top - 11
Next xlColPoint
With xlWrkbk
.Save
.Close
End With
xlApp.Quit
Exit_CreateChart:
Set xlSourceRange = Nothing
Set xlColPoint = Nothing
Set xlChartObj = Nothing
Set xlWrkbk = Nothing
Set xlApp = Nothing
Exit Function
Err_CreateChart:
MsgBox CStr(Err) & " " & Err.Description
Resume Exit_CreateChart
End Function |