siliconlemon
siliconlemon

Reputation: 47

Referencing an ExcelApp Object Running in a Different Process (by A Different User) in VB6

My app is supposed to take user inputs and archive them in Excel files.

All of that would work if I didn't need to access said Excel files as a special user due to the company's safety restrictions.

I have working code that opens said restricted files through creating a new process (it is pretty much the same as the one here).

I use the code as such:

Sub RunAsUser_Main()
    Dim ExeCommand As String
    ExeCommand = "C:\Program Files\Microsoft Office\Office16\EXCEL.EXE \\192.168.88.3\share\public\Workbook.xlsm"
    RunAsUser "username", "password", "domain", ExeCommand, "C:\Windows"
    
'-------------------- OPEN WORKBOOK --------------------
    Dim ret As Integer
    Dim ExcelApp As Object
    Dim WorkbookPath As String
    Dim MyWorkbook As Object
    
    On Error Resume Next
    Set ExcelApp = GetObject("Excel.Application").Application
    If ExcelApp Is Nothing Then
        ret = MsgBox("error!", vbCritical + vbOKOnly, title)
        Exit Sub
    End If
...

All goes well until the GetObject statement. The new process starts, Excel opens the workbook as it should and I have verified that it is run by the special user.
After this, I am unable to reference the running ExcelApp object. It returns nothing.

I've also used the code from this thread that is supposed to list all current instances of Excel. It does list the ones running under my current user, but doesn't register the one under my special user.

Upvotes: 2

Views: 100

Answers (0)

Related Questions