PC Review


Reply
Thread Tools Rate Thread

custom toolbars to exclusive files.

 
 
=?Utf-8?B?UGV0ZXIgTGVl?=
Guest
Posts: n/a
 
      16th Apr 2007
In Excel 2003,

I was wonder if it was possible to make a custom toolbar to only open in one
file.
Basically, the toolbar is exclusive to the one file.

I don't want to just hide it. I want the toolbar only to work on that one
file and not even exist on other files.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      16th Apr 2007
Peter,

You can create the toolbar everytime the workbook activates and delete it on
deactivate event. Somewhat like this

Private Sub Workbook_Activate()
Dim cmdbar As CommandBar
Set cmdbar = Application.CommandBars.Add("MyCommandBar")
cmdbar.Visible = True
cmdbar.Position = msoBarTop
With Application.CommandBars("Standard")
.Controls(1).Copy bar:=cmdbar
.Controls(2).Copy bar:=cmdbar
End With
End Sub

Private Sub Workbook_Deactivate()
On Error Resume Next
Application.CommandBars("MyCommandBar").Delete
End Sub



--
Hope that helps.

Vergel Adriano


"Peter Lee" wrote:

> In Excel 2003,
>
> I was wonder if it was possible to make a custom toolbar to only open in one
> file.
> Basically, the toolbar is exclusive to the one file.
>
> I don't want to just hide it. I want the toolbar only to work on that one
> file and not even exist on other files.
>

 
Reply With Quote
 
=?Utf-8?B?TnV6emE=?=
Guest
Posts: n/a
 
      16th Apr 2007
Hi Vergel,

Your response was helpful for me but unfortunately it didn't work when I
tried it. I'm using Excel 2003.

I created the toolbar also named "MyCommandBar", then in Visual Basic Editor
pasted your code in the "ThisWorkbook" object. When I closed then reopened
the file, my toolbar had changed and the buttons I had on there were removed,
and replaced by the "New" and "Open" icons. Even when I fixed up the icons on
my toolbar again to the buttons that I want, then close and open the file,
the toolbar reappears with the "New" and "Open" icons and doesn't seem to
save my changes.

Any suggestions with this please?

"Vergel Adriano" wrote:

> Peter,
>
> You can create the toolbar everytime the workbook activates and delete it on
> deactivate event. Somewhat like this
>
> Private Sub Workbook_Activate()
> Dim cmdbar As CommandBar
> Set cmdbar = Application.CommandBars.Add("MyCommandBar")
> cmdbar.Visible = True
> cmdbar.Position = msoBarTop
> With Application.CommandBars("Standard")
> .Controls(1).Copy bar:=cmdbar
> .Controls(2).Copy bar:=cmdbar
> End With
> End Sub
>
> Private Sub Workbook_Deactivate()
> On Error Resume Next
> Application.CommandBars("MyCommandBar").Delete
> End Sub
>
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "Peter Lee" wrote:
>
> > In Excel 2003,
> >
> > I was wonder if it was possible to make a custom toolbar to only open in one
> > file.
> > Basically, the toolbar is exclusive to the one file.
> >
> > I don't want to just hide it. I want the toolbar only to work on that one
> > file and not even exist on other files.
> >

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      16th Apr 2007
Hi Nuzza,

The example that I provided was just to demo how to create a toolbar when a
workbook is activated and delete that same toolbar when the workbook is
deactivated. For that purpose, the code creates a toolbar with the first two
buttons copied from the standard toolbar. Here is the Workbook_Activate code
with some comments so you can fit it in your own code.

Private Sub Workbook_Activate()
Dim cmdbar As CommandBar

'create the toolbar
Set cmdbar = Application.CommandBars.Add("MyCommandBar")

'make it visible and docked on top
cmdbar.Visible = True
cmdbar.Position = msoBarTop

'copy the first two buttons in the Standard toolbar to my toolbar
'replace this part with your own code to create your buttons.
With Application.CommandBars("Standard")
.Controls(1).Copy bar:=cmdbar
.Controls(2).Copy bar:=cmdbar
End With

End Sub

--
Hope that helps.

Vergel Adriano


"Nuzza" wrote:

> Hi Vergel,
>
> Your response was helpful for me but unfortunately it didn't work when I
> tried it. I'm using Excel 2003.
>
> I created the toolbar also named "MyCommandBar", then in Visual Basic Editor
> pasted your code in the "ThisWorkbook" object. When I closed then reopened
> the file, my toolbar had changed and the buttons I had on there were removed,
> and replaced by the "New" and "Open" icons. Even when I fixed up the icons on
> my toolbar again to the buttons that I want, then close and open the file,
> the toolbar reappears with the "New" and "Open" icons and doesn't seem to
> save my changes.
>
> Any suggestions with this please?
>
> "Vergel Adriano" wrote:
>
> > Peter,
> >
> > You can create the toolbar everytime the workbook activates and delete it on
> > deactivate event. Somewhat like this
> >
> > Private Sub Workbook_Activate()
> > Dim cmdbar As CommandBar
> > Set cmdbar = Application.CommandBars.Add("MyCommandBar")
> > cmdbar.Visible = True
> > cmdbar.Position = msoBarTop
> > With Application.CommandBars("Standard")
> > .Controls(1).Copy bar:=cmdbar
> > .Controls(2).Copy bar:=cmdbar
> > End With
> > End Sub
> >
> > Private Sub Workbook_Deactivate()
> > On Error Resume Next
> > Application.CommandBars("MyCommandBar").Delete
> > End Sub
> >
> >
> >
> > --
> > Hope that helps.
> >
> > Vergel Adriano
> >
> >
> > "Peter Lee" wrote:
> >
> > > In Excel 2003,
> > >
> > > I was wonder if it was possible to make a custom toolbar to only open in one
> > > file.
> > > Basically, the toolbar is exclusive to the one file.
> > >
> > > I don't want to just hide it. I want the toolbar only to work on that one
> > > file and not even exist on other files.
> > >

 
Reply With Quote
 
=?Utf-8?B?TnV6emE=?=
Guest
Posts: n/a
 
      16th Apr 2007
Thanks, this works better.

So would this work if another user accesses the file? Is there a way that I
can store the toolbar in the spreadsheet only, and not have to reference to
another toolbar? Basically, to go back to the original question of this
thread, I want this toolbar to open only in this one file and closed when the
file is closed.
 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      16th Apr 2007
Hi Nuzza,

Yes, I believe it should work if another user opens the file.

You don't really store the toolbar in the spreadsheet. But you can put code
on the spreadsheet that creates and/or displays the toolbar. The OP was
looking for a way to make a toolbar available only to one specific workbook.
If the user closes the workbook or switches to another one, he should not see
the toolbar. The OP didn't want to just hide the toolbar. It should not exist
unless the user is on the specific workbook. Thus, my suggestion was to
create the toolbar when the workbook is activated and delete the toolbar on
workbook_deactivate.

In your case, if you don't want the toolbar being deleted, you can just hide
it on the workbook_deactivate. For example:

Private Sub Workbook_Deactivate()
On Error Resume Next
Application.CommandBars("MyCommandBar").Visible=False
End Sub


--
Hope that helps.

Vergel Adriano


"Nuzza" wrote:

> Thanks, this works better.
>
> So would this work if another user accesses the file? Is there a way that I
> can store the toolbar in the spreadsheet only, and not have to reference to
> another toolbar? Basically, to go back to the original question of this
> thread, I want this toolbar to open only in this one file and closed when the
> file is closed.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ldb files exclusive Jo Microsoft Access 3 9th May 2008 03:26 AM
Custom toolbars for specific files Coolboy55 Microsoft Excel Programming 1 14th Mar 2006 09:36 PM
custom toolbars Alec Stonehouse Microsoft Powerpoint 2 13th Jun 2005 12:28 PM
Using ODC files always locks exclusive cerfingnow Microsoft Excel Discussion 2 10th Nov 2004 12:32 PM
Exclusive access and .ldb files John P. Microsoft Access Security 5 31st Oct 2003 07:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 AM.