Macro Excel in Access module

  • Thread starter Thread starter Patrice
  • Start date Start date
P

Patrice

Hi,

I'd like to run an Excel macro in an Access module. I did like that:

Set objXL = CreateObject("Excel.Application")
Set objWkb = objXL.Workbooks.Open(MyWorkBook)
Set objSht = objWkb.Worksheets(MySheet)

Rows("1:5" ).Select

'After that it is not working from Access
'But it's working if it's directly written in Excel

Selection.Delete Shift:=xlUp

I tried like that too

With objWkb
With objSht.Selection
.Delete Shift:=xlUp
End With
End With

But it's not working. So my question is How can I do to work with a Excel
selection true Access.

Also I tried to Run an Excel macro from Acces like that

strFile = MyXL.Run("MyWorkBook.xls!MyExcelMacro")

It's working but I don't know how to pass parameters to the ExcelMacro??

If some body can answer one of those questions It would make my day

Tank you very much

Patrice
 
The problem is that you're not referring to the Excel-related objects you've
instantiated. For example,

Rows("1:5" ).Select

needs to be

objSht.Rows("1:5" ).Select

I believe what you want is

objSht.Rows("1:5").Delete Shift = xlUp

See http://support.microsoft.com/kb/153307 for your second issue.
 
Back
Top