Hi everyone,
I am currently writing an Access module that first exports a table to Excel, then uses an Excel object for further formatting inside Excel.
After the file is exported and created (which works fine), I initialize an Excel object like this:
which also works fine. Now, I can use basic Excel commands as I would expect, for example:
However, now I am trying to create a diagram from scratch from the data already present in the sheet.
The recorded Excel macro code is as follows:
Now this is where the trouble starts. I tried to run this code from Access in a basic
environment, but Access cannot interpret the lines with a := correctly, and I get an "incompatible types" warning in the line "ActiveChart.ChartType = xlLine"
Intuitively, that actually makes sense, since "xlLine" is not defined in Access, and := could well clash with Access' syntax in such a case.
So my questions:
1) Is there a way to run such Excel commands from Access?
2) Failing that, is there a way to create, save and then run an Excel macro from scratch out of Access? (I know how to run an existing Excel macro from Access, but couldn't find anything on creating a new one. I'd prefer not to use additional files apart from the .mdb and target .xls. Temp files would be fine though)
Thanks in advance for any help you can provide, I've been scouring the net for the past 90 minutes but couldn't find any relevant info, and that was a pretty lousy way to spend a Friday afternoon in the office
Bani
I am currently writing an Access module that first exports a table to Excel, then uses an Excel object for further formatting inside Excel.
After the file is exported and created (which works fine), I initialize an Excel object like this:
Code:
Set xlAnw = CreateObject("excel.application")
xlAnw.Visible = False
xlAnw.Workbooks.Open FileName:=ee_filename
which also works fine. Now, I can use basic Excel commands as I would expect, for example:
Code:
xlAnw.Sheets("DayAnalysis").Select
xlAnw.Rows("1:1").Select
However, now I am trying to create a diagram from scratch from the data already present in the sheet.
The recorded Excel macro code is as follows:
Code:
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Tagesanalyse").Range("A2:B254"), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Tagesanalyse"
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Characters.Text = "Zugriffsverlauf"
ActiveChart.Axes(xlCategory, xlPrimary).HasTitle = True
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Anzahl"
ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Datum"
ActiveSheet.Shapes("Diagramm 1").IncrementLeft 4.5
ActiveSheet.Shapes("Diagramm 1").IncrementTop -109.5
ActiveWindow.Visible = False
Now this is where the trouble starts. I tried to run this code from Access in a basic
Code:
With xlAnw
.Charts.Add
.ActiveChart.[...]
[...]
End With
environment, but Access cannot interpret the lines with a := correctly, and I get an "incompatible types" warning in the line "ActiveChart.ChartType = xlLine"
Intuitively, that actually makes sense, since "xlLine" is not defined in Access, and := could well clash with Access' syntax in such a case.
So my questions:
1) Is there a way to run such Excel commands from Access?
2) Failing that, is there a way to create, save and then run an Excel macro from scratch out of Access? (I know how to run an existing Excel macro from Access, but couldn't find anything on creating a new one. I'd prefer not to use additional files apart from the .mdb and target .xls. Temp files would be fine though)
Thanks in advance for any help you can provide, I've been scouring the net for the past 90 minutes but couldn't find any relevant info, and that was a pretty lousy way to spend a Friday afternoon in the office
Bani