set function

Tren2k

New Member
Joined
Jan 25, 2008
Messages
14
Hi Guys

I'm opening another workbook via vb and it want it to remain open and accessible whilst this workbook is open

Set databook = CreateObject("excel.Application")

databook.Workbooks.Open Filename:= _
("N:\databaseinfo.xls"), _
local:=True
databook.Visible = False
databook.Application.DisplayAlerts = False

im opening the wb as above, but when i move onto a different module 'databook' is no longer accessing the open book. Is there anyway to keep databook open for all modules?

Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
How do you declare databook? It should be in a general code module:-
Code:
Public databook As Excel.Application
Then declare a Public variable As Workbook and open the workbook thus:-
Code:
Set [I]variable[/I]=databook.Workbooks.Open
I think that should do what you're asking.

PS. The name databook is a bit misleading as this actually points to the Excel application itself, rather than a workbook.
 
Last edited:
Upvote 0
Why are using another session of Excel?
If you dim database as workbook at the top, you can then use?
set databook=workbooks.open("N:\databaseinfo.xls")

This will open the workbook for you and you can then use things like:-
databook.visible=false
so it's still hidden.
 
Upvote 0
Thanks guys, basically this is just a small company contacts database which was all stored in one file, however different people saving it over the network on x64 and x86 machines are causing it to crash for others when reopening, therefore I was planning to just keep the data in a separate sheet so the file with all the code in is never saved over.

it doesnt have to be called databook. i just want it to open when i open the main workbook with the code in and stay open so the data can be updated until i close the main workbook
 
Upvote 0
As long as you keep the name consistent through the code and dim it as a workbook, the code will work fine.

You could even make it a public variable is you have lots of code that might refer to it.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,716
Members
452,939
Latest member
WCrawford

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