Thanks guys, I really appreciate your assistance. I am still not sure what to
try. These are samples of my Access and Excel procedures:
My Excel sub looks similar to:
Sub GET_CURR_YEAR_FROM_ACCESS()
Dim CURR_YEAR As Integer
Sheets.Add
Sheets("Sheet1").Name = "REFERENCE"
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("REFERENCE").Range( _
"A2"), PlotBy:=xlRows
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = _
"={""JAN"","" FEB"","" MAR"","" APR"","" MAY"","" JUN"","" JUL"",""
AUG"","" SEP"","" OCT"","" NOV"","" DEC""}"
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="SCR NET INCOME %"
'This is where I need to use CURRENT YEAR value entered
' by a user on Access form
'Title
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "SCR Sales Offices Current Pendings "
& CURR_YEAR
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End Sub
My Access sub looks similar to:
Sub PASS_CURRENT_YEAR()
Dim CURR_YEAR As Integer
Dim OBJ As Object
Set OBJ = GetObject(, "EXCEL.APPLICATION")
CURR_YEAR = Forms!FORMNAME.Box0
‘I need to figure out a way to pass CURR_YEAR value from form to following
excel macro
OBJ.Application.Run "PERSONAL.XLS!GET_CURR_YEAR_FROM_ACCESS"
End Sub
> hi,
> without seeing the xl macro code and your access code, i
[quoted text clipped - 30 lines]
> >
> >.
John Nurick - 02 Mar 2005 07:26 GMT
Hi Brent,
1) In your Access application, go to Tools|References and set a refernce
to the Microsoft Excel X.X Object Library. This makes the VBA
intellisense system recognise Excel objects Then change
> Dim OBJ As Object
> Set OBJ = GetObject(, "EXCEL.APPLICATION")
to something like:
Dim objXL As Excel.Application
Dim wbkW As Excel.Workbook
Dim wksW As Excel.Worksheet
Dim xlChart As Excel.Chart
Dim intCurrYear As Integer
Set objXL = CreateObject("Excel.Application")
Set wbkW = objXL.Workbooks.Open("location of your file")
Next paste your existing Excel code into the Access VB editor, and
modify it so it will run in Access while controlling Excel. For
instance, in Excel you've used things like
Sheets.Add
while here you need to be more explicit, e.g.
Set wksW = wbkW.Worksheets.Add
wksW.Name = "REFERENCE"
Set xlChart = wbkW.Charts.Add
With xlChart
.ChartType = xlLine
.SetSourceData blah blah
...
End With
...
'next line works because this code is running in Access
intCurrYear = CInt(Forms("FORMNAME").Controls("Box0").Value)
...
wbkW.Save
wbkW.Close
objXL.Quit False
>Thanks guys, I really appreciate your assistance. I am still not sure what to
>try. These are samples of my Access and Excel procedures:
[quoted text clipped - 73 lines]
>> >
>> >.
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
Brent E - 02 Mar 2005 16:45 GMT
Terrific, Thanks John.
> Hi Brent,
>
[quoted text clipped - 125 lines]
>
> Please respond in the newgroup and not by email.
I forgot to mention, I know I could probably program graphs in Access, but I
do not know how to program graphs in Access very well and I know Excel
better. I also use Excel because I can record a macro and Excel writes code
for me. That is why I am using Excel.
> hi,
> without seeing the xl macro code and your access code, i
[quoted text clipped - 30 lines]
> >
> >.