0

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

1
  • Access VBA can run any Excel VBA. You'll just have to call the appropriate objects and constants. Personally, I try to never run anything in Excel. As a relational database, Access has a more robust application and automation environment with a SQL engine, GUI interface builder, and reporting generator, much better tool than a flatfile spreadsheet. Commented Aug 7, 2015 at 0:04

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

No reference needed if you use late binding (especially when users can have different versions): Dim appExcel as Object Set appExcel=CreateObject("Excel.Application")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.