Hi John
Sorry to take so long to get back - the day job got in the way.
I set up a module in Access and tried this - it does work honest!
Sub controlExcel()
Dim xlapp As Object
Dim xlwb As Object
Dim xlws As Object
Dim rng As Range
Dim Y As Integer
' Create an instance of Excel and add a workbook
Set xlapp = CreateObject("Excel.Application")
Set xlwb = xlapp.Workbooks.Add
Set xlws = xlwb.Worksheets("Sheet1")
'Give the user control of Excel.
xlapp.UserControl = True
'Select Range According to John's requirements - i.e. the bit we did last time!
Y = 12 'Or whatever you want it to be.
Set rng = xlws.Range("A1").Resize(Y, 3)
rng.Select 'You should delete this line - I put it in so
'you could see what's happening to your range.
'Make the application visible to the user.
xlapp.Visible = True
' For needness I set the 3 Excel objects to nothing at the end of the routine.
' I'm told that this avoids memory leaks.
End Sub
I don't know how you set up your control, but I use the xlapp, xlwb and xlws sections as standard. You can then control Excel by prefixing it with the relevant object and treat it as if your code is native to the Excel application.
Hopefully this helps. It's always possible that someone much brighter than me knows better ways of doing this, but that's how I do it anyway!
Martin
Bookmarks