(Solved) – Activate a specific Workbook from a list of instances – I’m able to get the list of open Workbooks, but I cannot Activate a specific one

(solved)-–-activate-a-specific-workbook-from-a-list-of-instances-–-i’m-able-to-get-the-list-of-open-workbooks,-but-i-cannot-activate-a-specific-one

reference source of original code: Having multiple Excel instances launched, how can I get the Application Object for all of them?

The Excel Workbook that I’m trying to open is created by a database application for making changes.
Here is the code I’m using. The issue is that it creates a read-only copy. I need to be able to update (via a Macro from a different Workbook) the original Workbook. I appreciate any help I may get – Thank you.

Sub Test2XL()

        Dim Source_Table As Range, Source_Rows As Integer, Source_Columns As Integer, WbTCName As String
        Dim WbTC As Workbook

  Dim xl As Excel.Application
  Dim i As Integer

  For Each xl In GetExcelInstances()
    Debug.Print "Handle: " & xl.Application.hwnd
    Debug.Print "# workbooks: " & xl.Application.Workbooks.Count
    For i = 1 To xl.Application.Workbooks.Count
        Debug.Print "Workbook: " & xl.Application.Workbooks(i).Name
        Debug.Print "Workbook: " & xl.Application.Workbooks(i).FullName
        Debug.Print "Workbook path: " & xl.Application.Workbooks(i).Path
        If Left(xl.Application.Workbooks(i).Name, 3) = "tc_" Then  ' Find Workbook of Interest
            WbTCName = xl.Application.Workbooks(i).FullName
            On Error Resume Next
            Set WbTC = Workbooks(WbTCName)
            On Error GoTo 0
            If WbTC Is Nothing Then
                Set WbTC = Workbooks.Open(WbTCName)
            End If
        End If
    Next i
  Next
  Set xl = Nothing


End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *