Jump to content

Recommended Posts

Posted (edited)

Quick question, when working with Excel, does each workbook require its own Excel instance, or can multiple workbooks be opened off of the same Excel instance? I tested both ways, on the surface they both seemed to work, just thought I'd ask here to make sure before proceeding any further. Thanks!

Disclaimer: The following is pseudo code

$excel_instance1 = _Excel_Open()
$workbook1 = _Excel_BookOpen($excel_instance1, @ScriptDir & "\book1.xlsx")
$workbook2 = _Excel_BookOpen($excel_instance1, @ScriptDir & "\book2.xlsx")

Or

$excel_instance1 = _Excel_Open()
$workbook1 = _Excel_BookOpen($excel_instance1, @ScriptDir & "\book1.xlsx")
$excel_instance2 = _Excel_Open()
$workbook2 = _Excel_BookOpen($excel_instance2, @ScriptDir & "\book2.xlsx")

 

Edited by Rhidlor
added tags
Posted (edited)

@Rhidlor

You can use just an instance, since the object you are using is the Application object of Excel, quite the opposite for the Workbook object, which you can have separated files, so in that case they need to be threated in separate variables (as you're already doing) :)

Edited by FrancescoDiMuro

Click here to see my signature:

  Reveal hidden contents

 

Posted

Usually a single instance of Excel is enough.
But if a user and your script manipulate workbooks at the same time then it might be sensible to separate them by starting a new Excel instance for your script.
So you can make sure they do not interfere.

My UDFs and Tutorials:

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...