GetObject returning an error if the file is already open

JustGreat

New Member
Joined
Jun 16, 2010
Messages
2
Hello to all,

I have 2 Excel Workbooks (DataBase.xlsx and Program.xlsm)

DataBase.xlsx is a shared file located on a shared folder (Teams/Sharepoint). Program.xlsm is an Excel file located on user's PC.

Any User can insert and retrieve Data from the DataBase.xlsx.

I am using GetObject to open with an invisible way the DataBase.xlsx each time that a user wants to Add Or fetch Data.

The problem is that if the DataBase is already opened, the GetObject fails and returns an error : "File name or class name not found during Automation operation", but if it's already closed and I call GetObject there is no problem and the code works fine.

Also, if I place the DataBase.xlsx on a local folder (not the shared one), even if it's already opened I can still call the GetObject without any problem.

Is there anyway to solve this and to allow users to save and fetch data from an excel even if it's already opened by another one ?


Here is the part of my code where I am facing the problem :

VBA Code:
Dim SharedDataBaseWb As Workbook
Dim SharedDataBaseWs As Worksheet
Dim sDataBaseFolder As String
Dim sFileName As String
Dim sFullFileName As String

sDataBaseFolder = Params.Range("ParamsDBFolder").Value2
sFileName = "DataBase.xlsx"
sFullFileName = sDataBaseFolder & sFileName

Set SharedDataBaseWb = GetObject(sFullFileName) 'At this line I am getting the error

Set SharedDataBaseWs = SharedDataBaseWb.Worksheets("RawData")
 
End If

With SharedDataBaseWs
 'My code
 
End with
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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