Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code to locate the command bar number the printer button is on


What would be the simplest VBA code to locate the command bar numbe
that the printer command button is on & put the number into
variable.

I am trying to add two command buttons immediately after the printe
command button but it's on different command bars from computer t
computer.

For example, it may be on command bar #3 on one computer but on #4 o
another computer.

Thanks. I dream of a day when I would be half as good at VBA as yo
guys. Thanks, mikebur

--
mikebur
-----------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...fo&userid=2458
View this thread: http://www.excelforum.com/showthread.php?threadid=50700

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA code to locate the command bar number the printer button is on

Hi Mike,

The following version restricts operation to visible commandbars:

'=============
Public Sub TesterA001()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=4)
With Ctrl
If .Parent.Visible Then
MsgBox "Commandbar: " & .Parent.Name _
& " position = " & .Index
End If
End With
Next Ctrl
End Sub
'<<=============


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Mike,

As a starting point, try:

'=============
Public Sub TesterA001()
Dim Ctrl As Office.CommandBarControl
For Each Ctrl In Application.CommandBars.FindControls(ID:=4)
MsgBox "Commandbar: " & Ctrl.Parent.Name _
& " position = " &
Ctrl.Index
Next Ctrl
End Sub
'<<=============


---
Regards,
Norman



"mikeburg" wrote
in message ...

What would be the simplest VBA code to locate the command bar number
that the printer command button is on & put the number into a
variable.

I am trying to add two command buttons immediately after the printer
command button but it's on different command bars from computer to
computer.

For example, it may be on command bar #3 on one computer but on #4 of
another computer.

Thanks. I dream of a day when I would be half as good at VBA as you
guys. Thanks, mikeburg


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile:
http://www.excelforum.com/member.php...o&userid=24581
View this thread:
http://www.excelforum.com/showthread...hreadid=507006





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code to locate the command bar number the printer button is on


Thanks a lot.

The 1st answer gave all command bars.

The 2nd answer would not show anything. However, I do need the printe
command button's visible command bar number. Any ideas how to correc
the 2nd answer.

By the way, I am using Excel XP (version 2002, I think).

Thanks a million, mikebur

--
mikebur
-----------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...fo&userid=2458
View this thread: http://www.excelforum.com/showthread.php?threadid=50700

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA code to locate the command bar number the printer button is on

Hi Mike,

The 2nd answer would not show anything. However, I do need the printer
command button's visible command bar number. Any ideas how to correct
the 2nd answer.


Testing, the second macro returned the following message:

Commandbar: Standard position: 5


---
Regards,
Norman



"mikeburg" wrote in
message ...

Thanks a lot.

The 1st answer gave all command bars.

The 2nd answer would not show anything. However, I do need the printer
command button's visible command bar number. Any ideas how to correct
the 2nd answer.

By the way, I am using Excel XP (version 2002, I think).

Thanks a million, mikeburg


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile:
http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=507006



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code to locate the command bar number the printer button is on


Could you check the code on this post again? For the life of me, I
can't get it to do anything. I've tried copying it as well as retyping
it.

Sorry for the trouble. Thanks, mikeburg


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=507006



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA code to locate the command bar number the printer button is on

Hi Mike,

Could you check the code on this post again? For the life of me, I
can't get it to do anything. I've tried copying it as well as retyping
it.


The code works for me - in my previous post, I reported the msgbox response
verbatim.

Furthermore, similar code worked for you:

The 1st answer gave all command bars.


The only difference between the two suggested macros is that the first
reports instances of the print control on all commandbars whilst the second
reports only on visible commandbars.

Are you sure, therefore, that you have a print control on a visible
commandbar?


---
Regards,
Norman


  #7   Report Post  
Posted to microsoft.public.excel.programming
JK JK is offline
external usenet poster
 
Posts: 7
Default VBA code to locate the command bar number the printer button is on

Hi,

I used Norman's code and developed it a bit further.
It saves the Index of the Print (and checks it's not Print Preview)
into
a variable called intIndex.
I tested with Print-control in different positions in the
'Standard'-cmdBar
and it works.

***
Public Sub TesterA001()
Dim Ctrl As Office.CommandBarControl
Dim intIndex As Integer

For Each Ctrl In Application.CommandBars("Standard").Controls
If Left(Ctrl.Caption, 5) = "Print" Then
If Left(Ctrl.Caption, 7) < "Print P" Then
intIndex = Ctrl.Index
End If
End If
Next Ctrl

End Sub
***

Hope this solves your problem

JK

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA code to locate the command bar number the printer button is on

Hi JK,

I used Norman's code and developed it a bit further.
It saves the Index of the Print (and checks it's not Print Preview)
into
a variable called intIndex.
I tested with Print-control in different positions in the
'Standard'-cmdBar
and it works.


My code should locate instances of the Print control on any visible toolbar
whereas your code limits any search to a single toolbar. Additionally, if
the user employed a non-English language version of Excel (using an
alternative name), your code adaptation would fail to disclose any instance
of the control.

The control id for the print control (4) is unique to that control and no
confusion with the Print Preview control (whose unique id is 109) should be
possible. In any event, a search based on a unique id should be
intrinsically more reliable than a search based on the control's caption,
which depends on the version language and can be altered using VBA.


---
Regards,
Norman



"JK" wrote in message
oups.com...
Hi,

I used Norman's code and developed it a bit further.
It saves the Index of the Print (and checks it's not Print Preview)
into
a variable called intIndex.
I tested with Print-control in different positions in the
'Standard'-cmdBar
and it works.

***
Public Sub TesterA001()
Dim Ctrl As Office.CommandBarControl
Dim intIndex As Integer

For Each Ctrl In Application.CommandBars("Standard").Controls
If Left(Ctrl.Caption, 5) = "Print" Then
If Left(Ctrl.Caption, 7) < "Print P" Then
intIndex = Ctrl.Index
End If
End If
Next Ctrl

End Sub
***

Hope this solves your problem

JK



  #9   Report Post  
Posted to microsoft.public.excel.programming
JK JK is offline
external usenet poster
 
Posts: 7
Default VBA code to locate the command bar number the printer button is on

Norman Jones wrote:
Hi JK,

My code should locate instances of the Print control on any visible toolbar
whereas your code limits any search to a single toolbar. Additionally, if
the user employed a non-English language version of Excel (using an
alternative name), your code adaptation would fail to disclose any instance
of the control.

The control id for the print control (4) is unique to that control and no
confusion with the Print Preview control (whose unique id is 109) should be
possible. In any event, a search based on a unique id should be
intrinsically more reliable than a search based on the control's caption,
which depends on the version language and can be altered using VBA.


---
Regards,
Norman


Hi Norman,

you're absolutely right. I was thinking that the need was to insert it
into the 'Standard' bar (and in English).
I also didn't remember that control id thing. Inspired by your reply I
now have the list of control IDs in my bookmarks. :)
But the ID for 'Print' in the 'Standard' toolbar is 2521 instead of 4
(Office 2000).
(http://support.microsoft.com/default...BLN%5D;Q213552)
Weird...

Thanks anyways,

JK

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
command button code dummy Excel Discussion (Misc queries) 2 December 1st 09 02:57 PM
VBA code behind command button [email protected] Excel Worksheet Functions 1 March 22nd 06 08:13 PM
VBA code to locate the command bar number the printer button is on Norman Jones Excel Programming 0 February 1st 06 12:57 AM
Command Button VBA code Dave Peterson Excel Discussion (Misc queries) 2 January 25th 05 11:28 PM
Create Command Button from Code Bruce B[_2_] Excel Programming 0 July 14th 03 02:01 PM


All times are GMT +1. The time now is 06:04 AM.

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

About Us

"It's about Microsoft Excel"