force file to open in dedicated instance

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,907
Office Version
  1. 365
Platform
  1. Windows
Hi All

I'm trying to force a particular file to open in its own dedicated instance of the Excel application. The macro below checks how many other files are open (by counting visible windows). If no other files are open then no problem. However, if there are other files open then it needs to re-open in a new instance and then close ThisWorkbook. This bit is ok but (naturally) the file opens in read only.

Code:
Option Explicit
Sub auto_open()
    Dim win As Window
    Dim lngCount As Long
 
    For Each win In Application.Windows
        lngCount = lngCount - win.Visible
    Next win
 
    If lngCount = 1 Then GoTo Finish
 
    With CreateObject("Excel.Application")
        .Visible = True
        '.DisplayAlerts = False
        Call .Workbooks.Open(ThisWorkbook.FullName)
    End With
 
    ThisWorkbook.Close False 'this should still trigger the before_close routine
    Exit Sub 'don't actually need this
 
Finish:
    '//call User Interface routine here
    ThisWorkbook.SaveAs ThisWorkbook.FullName 'won't trigger if file is opened through this routine
End Sub

Does anybody have an idea how to make the file open in write mode. I tried adding a SaveAs statement to save over itself but it won't allow it. The auto_open macro isn't triggered when the file is reopened with this macro.
 
Jon,
I have a situation almost identical to yours, which I just posted separately. How did you solve this? When I tested your code, it did not force a dedicated instance of Excel.


Check my post in this thread on how to ensure a workbook is always open in a seperate instance. I hope it achieves what you want.
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top