Kazschuri
Kazschuri

Reputation: 620

Easy way of using excel vba in access vba

I have a fairly big piece of excel vba code that I need to run. The problem is, that I need to start it from Access and the company security does not allow the starting of makros from an external trigger.

So I can start the excel code when in excel but I need to basically have to open the spreadsheet and have access do the same work that the excel code does.

Can I just copy the code and have it all run in Access and just somehow tell it that "ActiveChart" and "WorkSheets("XY")" are within Excel file "Z"?

Thanks

Kaz

Upvotes: 0

Views: 695

Answers (1)

Mark Butler
Mark Butler

Reputation: 895

Use an instance of Excel in your Access VBA:

You will need to set a reference to the Microsoft Excel 15.0 Object Library

Dim appExcel As Excel.Application
Dim wrkBook As Excel.Workbook

Set appExcel = New Excel.Application
Set wrkBook = appExcel.Workbooks.Open("C:\test.xlsx")

wrkBook.Worksheets("Sheet 1").Activate

With wrkBook.ActiveSheet

.... etc.

Upvotes: 2

Related Questions