Anscheinend war ich falsch und Sie können von außen auf ActiveSth-Objekte verweisen.
Dieser Code benötigt einen Verweis auf Microsoft Excel xy.0 Object Libary
und Microsoft Office xy.0 Object Libary
in "VBA-Editor -> Tools -> Verweise" oder definiert explizit das Excel-Enum (z. B. xlLineMarkers).
Sub cmdTransfer_Click() Dim sExcelWB As String Dim xl As Object ''Excel.Application Dim wb As Object ''Excel.Workbook Dim ws As Object ''Excel.Worksheet Dim ch As Object ''Excel.Chart Dim myRange As Object Set xl = CreateObject("excel.application") sExcelWB = "D:\testing2\" & "_qry_task.xls" DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_task", sExcelWB, True Set wb = xl.Workbooks.Open(sExcelWB) 'Sheets are named with the Access query name Set ws = wb.Sheets("qry_task") Set ch = xl.Charts.Add ch.ChartType = xlColumnClustered with ch 'Main Title from sheet "qry_task" in top of the Chart .HasTitle = True .ChartTitle.Text = ws.Range("A1").Value & " " & ws.Range("A2").Value & " " & ws.Range("D1").Value .Axes(xlValue).MajorGridlines.Delete .Axes(xlCategory, xlPrimary).HasTitle = False .Axes(xlValue, xlPrimary).HasTitle = False End With 'SubTitle below First Title from Sheet qry_task 'From txtboxes from the Form. '(txt_from – txt_to) 'chart_position_upper_left_corner Macro With wb .ActiveSheet.Shapes("Chart 1") .Left = .Range("A1").Left .Top = .Range("A1").Top .ActiveSheet.Shapes("Chart1").IncrementLeft -375.75 .ActiveSheet.Shapes("Chart 1").IncrementTop -96 .ActiveSheet.Shapes("Chart 1").ScaleWidth 1.3354166667, msoFalse, _ msoScaleFromTopLeft .ActiveSheet.Shapes("Chart 1").ScaleHeight 1.3177085156, msoFalse, _ msoScaleFromTopLeft 'insert secundary axis() .ActiveSheet.ChartObjects("Chart 1").Activate .ActiveChart.PlotArea.Select .ActiveChart.FullSeriesCollection(2).Select .ActiveChart.FullSeriesCollection(2).AxisGroup = 2 .ActiveChart.FullSeriesCollection(2).Select .ActiveChart.FullSeriesCollection(2).ChartType = xlLineMarkers .ActiveChart.FullSeriesCollection(1).Select .ActiveChart.ChartGroups(1).GapWidth = 69 .ActiveChart.FullSeriesCollection(2).Select .Application.CommandBars("Format Object").Visible = False .ActiveSheet.Shapes("Chart 1").ScaleWidth 1.5180265655, msoFalse, _ msoScaleFromTopLeft 'Chart labels 'Chart labels .ActiveSheet.Shapes("Chart 1").ScaleHeight 1.1797101449, msoFalse, _ msoScaleFromTopLeft .ActiveChart.FullSeriesCollection(2).Select .ActiveChart.ChartGroups(1).GapWidth = 48 .ActiveChart.FullSeriesCollection(1).Select .ActiveChart.SetElement (msoElementDataLabelShow) .ActiveChart.SetElement (msoElementDataLabelInsideBase) With wb.ActiveChart.FullSeriesCollection(1).DataLabels.Format.TextFrame2.TextRange.Font.Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorBackground1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 .Transparency = 0 .Solid 'Edit Font .Format.TextFrame2.TextRange.Font.Bold = msoTrue With .Format.TextFrame2.TextRange.Font .NameComplexScript = "Arial" .NameFarEast = "Arial" .Name = "Arial" End With End With End Sub
Versuchen Sie dies, nicht getestet, nur ein kurzer Hack, vielleicht ist ein Ende damit, usw. fehlen.