Ernesto
Ernesto

Reputation: 609

VBA and Excel running in parallel

This is a question that I have always had but never really gave it much though.

What I have at the moment is a worksheet that displays data, and the user refreshes whenever needed. So:

  1. User triggers a VBA Function
  2. VBA Function gathers data and analyses WHILE USER WAITS
  3. VBA Function dumps the result on the spreadsheet
  4. User continues viewing data

Since the data analysis is all done internally in VBA (No use of workbook, only recordsets, arrays, library etc.) I wanted to somehow be able to allow the user to continue viewing the original data, while VBA works on getting and analyzing new data.

I know you cant use the workbook AND run VBA at the same time, but you can however, have two excel instances and work on one workbook while the other runs VBA.

So could I somehow have my original excel instance call another excel instance and have it run the VBA while I work on my first instance?

Any Ideas?

(Also, not sure if the tag "Multithreading" is technically correct)

Upvotes: 1

Views: 4911

Answers (2)

AnalystCave.com
AnalystCave.com

Reputation: 4974

First thing - there is no multithreading for VBA in Excel. Second thing - since Excel 2007, Excel supports multithreaded recalculation of formulas.

Therefore to approach multithreading calculations in Excel you can do at least 2 things:

  1. Create a second instance of Excel (new Application instance! Not a new workbook within the same Application!) and execute the macro remotely.
  2. Create UDF functions (User Defined Functions) in VBA. Unfortunately you cannot edit other cells using UDF but you can save the results of your computations in a Global variable and then print the results.

My recommendation - go with option 2.

Upvotes: 1

scrimshander
scrimshander

Reputation: 11

I haven't been able to try this, but it seems like you can launch Excel from VBA using Application.FollowHyperLink. The hyperlink would have to be the local path to the sheet. You might have to use VBA to also make a copy of the sheet first.

Have you thought through the concurrency issues with having two copies?

Upvotes: 0

Related Questions