View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
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