Кажется, я ошибся, и вы можете ссылаться на объекты ActiveSth извне.
Этот код нуждается в ссылке Microsoft Excel xy.0 Object Libary
и Microsoft Office xy.0 Object Libary
в «VBA-Editor -> Tools -> References» или в явном виде определяет перечисления Excel (например, 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
Попробуйте это, не проверено, просто быстрый взлом, возможно, какой-то конец и т. Д. Отсутствуют.