Results 1 to 5 of 5

Thread: [RESOLVED] Help With Multiple Read-Only Instances of Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Resolved [RESOLVED] Help With Multiple Read-Only Instances of Excel

    Hi al,

    I am suffering with trying to figure out how to control multiple instances of Excel. I have an Excel Workbook (Basic Calculation Generator), which I would like to use to assess basic scenarios. You have several projects and costs have to be minimised.

    I have written code to open several instances of this project as below;

    Dim blnIsOpen As Boolean
    Dim blnReadOnly As Boolean
    Dim blnOpenRef As Boolean
    Dim wbRef As Workbook
    Dim xlApp As Excel.Application
    Dim wsWorking As Worksheet
    Dim strPath As String
    Dim sWorkbookToOpen As String
    Dim sWorkbook As String

    strPath = ThisWorkbook.Path & "\"
    sWorkbook = "Project.xlsm"
    sWorkbookToOpen = strPath & sWorkbook
    blnReadOnly = True


    On Error Resume Next
    Set wbRef = Workbooks(sWorkbook)
    On Error GoTo 0

    If wbRef Is Nothing Then
    Set xlApp = CreateObject("Excel.Application")
    Set wbRef = xlApp.Workbooks.Open(sWorkbookToOpen, , blnReadOnly)
    xlApp.Visible = True

    End If
    If blnOpenRef = True Then
    wbRef.Activate
    Else
    ' wsWorking.Activate
    End If
    Now I would like to control each instance that I have opened. As they are opened read-only and all have the same name, the stuff I have found online doesn't particularly prove to be very helpful.

    Also I would like to control each instance with different parameters. I.e. I would like to be able to put in data into project 1/project 2 which are different and then copy them from the "Project.xlsm" file into another file after getting the results from the Generator.

    What is the easiest way to go about this?

    Many thanks and I look forward to your advice.

    Also, what would be the easiest way of transferring data between these instances. Shall I create an object class where the data is pooled into a list or is there another way to do this?
    Last edited by maxzara; Feb 8th, 2012 at 07:52 AM.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Help With Multiple Read-Only Instances of Excel

    Welcome to VBForums

    Quote Originally Posted by maxzara View Post
    Now I would like to control each instance that I have opened. As they are opened read-only and all have the same name, the stuff I have found online doesn't particularly prove to be very helpful.
    Instead of the name of those sheets ,you could use the index they did get when opened.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help With Multiple Read-Only Instances of Excel

    Set xlApp = CreateObject("Excel.Application")
    each instance of excel should be set to a different object variable, or possibly a collection of excel instances, then each can have key, to reference it by, same probably applies to the workbook objects

    the collection or other variables should be declared at module level, so they remain in scope between procedures

    you can certainly use a class to do this, but i am not sure you really need to
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Exclamation Re: Help With Multiple Read-Only Instances of Excel

    Quote Originally Posted by westconn1 View Post
    each instance of excel should be set to a different object variable, or possibly a collection of excel instances, then each can have key, to reference it by, same probably applies to the workbook objects

    the collection or other variables should be declared at module level, so they remain in scope between procedures

    you can certainly use a class to do this, but i am not sure you really need to
    Thank you very much, that's exactly what I have done since. Should I create a new topic for handling the data processing issue?
    I have a series of data i.e. a list of prices (likely to be 120 records long), which need to be transferred from each individual instance of xlApp to the original. What is the best way of transferring these across? (Considering basic Copy/Paste does not work)

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] Help With Multiple Read-Only Instances of Excel

    Considering basic Copy/Paste does not work)
    it doesn't?
    you can assign values from one range to another across instances
    you can assign values from ranges into a 2d array
    then from the 2d array into another range
    i am surprised that copy and paste can not be made to work across instances, but if not the widows clipboard object could be used
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width