Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default how to check if more than one excel file is open?

Hello,

I have two questions that hopefully someone might have answers to.

First, i have created a plug in for excel that i use only when a specific
file is opened. The plug in also creates a toolbar to run this code. Is it
possible to only show the toolbar when that specific file is opened? I tried
to do it from "This workbook" in workbook_open sub, but it just doesn't show
the toolbar at all. I test for opened file, but for some reason it always
shows that the file isn't opened.

Second, when i click Exit on my userform after running the code, it closes
this workbook that i'm working with. That's fine when there's more than one
excel file open, but if this file is the only one that's open, i'd like to
use something like Application.Quit to close the application. How can i check
to see if there is more than one excel file open?

Thanks for all your help.

IB
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default how to check if more than one excel file is open?

With no code posted it is hard to comment, so I will just be very general.
When I create custom toolbars for a specific workbook I create one function
to create the toolbar and another oen to delete the toolbar. On open or on
workbook activeate I make a call to create the toolbar. On close or on
workbook deactiveate I make a call to delete the toolbar.

As for the second question
Workbooks.Count
will give you a count of the open workbooks. Careful with this though as you
may have a personal workbook open (where you are storing macros). You will
need to test to see if Personal.xls is open...

--
HTH...

Jim Thomlinson


"Graff" wrote:

Hello,

I have two questions that hopefully someone might have answers to.

First, i have created a plug in for excel that i use only when a specific
file is opened. The plug in also creates a toolbar to run this code. Is it
possible to only show the toolbar when that specific file is opened? I tried
to do it from "This workbook" in workbook_open sub, but it just doesn't show
the toolbar at all. I test for opened file, but for some reason it always
shows that the file isn't opened.

Second, when i click Exit on my userform after running the code, it closes
this workbook that i'm working with. That's fine when there's more than one
excel file open, but if this file is the only one that's open, i'd like to
use something like Application.Quit to close the application. How can i check
to see if there is more than one excel file open?

Thanks for all your help.

IB

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default how to check if more than one excel file is open?

Thanks for the quick reply Jim,

I'll try your suggestion for the second part in a bit.

As for the first question, let me try to explain the problem in greater
detail.

My code is in an add-in that is loaded every time any excel file is open, so
naturally the toolbar gets created any time any file is open. What i want to
do is to have the toolbar created only when the file i need to work with is
opened, and do nothing if any other excel file is open.

Here's what i tried, but it didn't work. It just doesn't show the toolbar at
all.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call deleteMenu
End Sub

Sub workbook_open()

Dim bk As Workbook

On Error Resume Next
Set bk = Workbooks("CombinedBatchStandardTransactions[1]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[2]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[3]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[4]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[5]")
If Not bk Is Nothing Then GoTo goOn

Exit Sub

goOn:

Call deleteMenu

Sheet1.Shapes("NL").Copy

Set MenuObject =
Application.CommandBars(1).Controls.Add(Type:=msoC ontrolPopup, befo=10,
temporary:=True)
MenuObject.Caption = "&NavSol"
Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton)
MenuItem.OnAction = "mdlInv.formdaily"
MenuItem.Caption = "&DBE"
MenuItem.PasteFace

End Sub

Sub deleteMenu()
On Error Resume Next
Application.CommandBars(1).Controls("NavSol").Dele te
On Error GoTo 0
End Sub

Is it not working because the file is not actually open yet? Can that be the
case?

Thanks again.

"Jim Thomlinson" wrote:

With no code posted it is hard to comment, so I will just be very general.
When I create custom toolbars for a specific workbook I create one function
to create the toolbar and another oen to delete the toolbar. On open or on
workbook activeate I make a call to create the toolbar. On close or on
workbook deactiveate I make a call to delete the toolbar.

As for the second question
Workbooks.Count
will give you a count of the open workbooks. Careful with this though as you
may have a personal workbook open (where you are storing macros). You will
need to test to see if Personal.xls is open...

--
HTH...

Jim Thomlinson


"Graff" wrote:

Hello,

I have two questions that hopefully someone might have answers to.

First, i have created a plug in for excel that i use only when a specific
file is opened. The plug in also creates a toolbar to run this code. Is it
possible to only show the toolbar when that specific file is opened? I tried
to do it from "This workbook" in workbook_open sub, but it just doesn't show
the toolbar at all. I test for opened file, but for some reason it always
shows that the file isn't opened.

Second, when i click Exit on my userform after running the code, it closes
this workbook that i'm working with. That's fine when there's more than one
excel file open, but if this file is the only one that's open, i'd like to
use something like Application.Quit to close the application. How can i check
to see if there is more than one excel file open?

Thanks for all your help.

IB

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default how to check if more than one excel file is open?

As we are dealing with an addin this is an entirely different matter. Your
addin has to respond to other files being opened. The events you are dealing
with are the events of the addin and not the events of the files being
opened. Check out this link on application level events...

http://www.cpearson.com/excel/AppEvent.aspx
--
HTH...

Jim Thomlinson


"Graff" wrote:

Thanks for the quick reply Jim,

I'll try your suggestion for the second part in a bit.

As for the first question, let me try to explain the problem in greater
detail.

My code is in an add-in that is loaded every time any excel file is open, so
naturally the toolbar gets created any time any file is open. What i want to
do is to have the toolbar created only when the file i need to work with is
opened, and do nothing if any other excel file is open.

Here's what i tried, but it didn't work. It just doesn't show the toolbar at
all.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call deleteMenu
End Sub

Sub workbook_open()

Dim bk As Workbook

On Error Resume Next
Set bk = Workbooks("CombinedBatchStandardTransactions[1]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[2]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[3]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[4]")
If Not bk Is Nothing Then GoTo goOn

Set bk = Workbooks("CombinedBatchStandardTransactions[5]")
If Not bk Is Nothing Then GoTo goOn

Exit Sub

goOn:

Call deleteMenu

Sheet1.Shapes("NL").Copy

Set MenuObject =
Application.CommandBars(1).Controls.Add(Type:=msoC ontrolPopup, befo=10,
temporary:=True)
MenuObject.Caption = "&NavSol"
Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton)
MenuItem.OnAction = "mdlInv.formdaily"
MenuItem.Caption = "&DBE"
MenuItem.PasteFace

End Sub

Sub deleteMenu()
On Error Resume Next
Application.CommandBars(1).Controls("NavSol").Dele te
On Error GoTo 0
End Sub

Is it not working because the file is not actually open yet? Can that be the
case?

Thanks again.

"Jim Thomlinson" wrote:

With no code posted it is hard to comment, so I will just be very general.
When I create custom toolbars for a specific workbook I create one function
to create the toolbar and another oen to delete the toolbar. On open or on
workbook activeate I make a call to create the toolbar. On close or on
workbook deactiveate I make a call to delete the toolbar.

As for the second question
Workbooks.Count
will give you a count of the open workbooks. Careful with this though as you
may have a personal workbook open (where you are storing macros). You will
need to test to see if Personal.xls is open...

--
HTH...

Jim Thomlinson


"Graff" wrote:

Hello,

I have two questions that hopefully someone might have answers to.

First, i have created a plug in for excel that i use only when a specific
file is opened. The plug in also creates a toolbar to run this code. Is it
possible to only show the toolbar when that specific file is opened? I tried
to do it from "This workbook" in workbook_open sub, but it just doesn't show
the toolbar at all. I test for opened file, but for some reason it always
shows that the file isn't opened.

Second, when i click Exit on my userform after running the code, it closes
this workbook that i'm working with. That's fine when there's more than one
excel file open, but if this file is the only one that's open, i'd like to
use something like Application.Quit to close the application. How can i check
to see if there is more than one excel file open?

Thanks for all your help.

IB

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for Open File! Ayo Excel Discussion (Misc queries) 2 August 11th 08 06:55 PM
check if file is already open mohavv Excel Discussion (Misc queries) 1 October 15th 07 12:08 AM
check if a file is open C[_4_] Excel Programming 6 March 31st 06 03:28 PM
execl to check if another excel file is open... ohboy! Excel Programming 4 July 20th 05 03:41 AM
How to check Excel file already Open Rudy S Excel Programming 2 January 25th 05 02:00 PM


All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"