ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Center Toolbar (https://www.excelbanter.com/excel-programming/386610-center-toolbar.html)

Zone

Center Toolbar
 
When my workbook opens, I make all commandbars invisible except the
standard menubar and the workbook's custom toolbar. I have the custom
toolbar in the right place vertically (just below the menubar). How
do I center it horizontally? TIA, James


Zone

Center Toolbar
 
On Mar 31, 12:22�pm, "Zone" wrote:
When my workbook opens, I make all commandbars invisible except the
standard menubar and the workbook's custom toolbar. *I have the custom
toolbar in the right place vertically (just below the menubar). *How
do I center it horizontally? *TIA, James


I mean, I want VBA to center my toolbar. J


Helmut Weber[_2_]

Center Toolbar
 
Hi James,

When my workbook opens, I make all commandbars invisible except the
standard menubar and the workbook's custom toolbar. I have the custom
toolbar in the right place vertically (just below the menubar). How
do I center it horizontally? TIA, James


for centering a toolbar:

Sub TestCenter()
Dim x As Long
Dim v As Long
v = Application.CommandBars("formatting").Width
x = System.HorizontalResolution
Application.CommandBars("formatting").Left = x / 2 - v / 2
End Sub

Though occasionally,
System.HorizontalResolution tells me,
that an ActiveX object could not be created.
Why? I don't know.
--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


Zone

Center Toolbar
 
On Mar 31, 2:51�pm, Helmut Weber wrote:

Helmut, line
x = System.HorizontalResolution
gives me run-time error 424, object required. I am using Excel 2002
on Windows XP. James

Hi James,

When my workbook opens, I make all commandbars invisible except the
standard menubar and the workbook's custom toolbar. *I have the custom
toolbar in the right place vertically (just below the menubar). *How
do I center it horizontally? *TIA, James


for centering a toolbar:

Sub TestCenter()
Dim x As Long
Dim v As Long
v = Application.CommandBars("formatting").Width
x = System.HorizontalResolution
Application.CommandBars("formatting").Left = x / 2 - v / 2
End Sub

Though occasionally,
System.HorizontalResolution tells me,
that an ActiveX object could not be created.
Why? I don't know.
--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




Helmut Weber[_2_]

Center Toolbar
 
Hi James,

there must be a bug in it.
I got the same message a few times,
then it disappeared.

I never get it in Word.

If the macro is just for you,
you may try it with 1024 or 1200 or whatever.

And it applies to a maximized window.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"



Zone

Center Toolbar
 
On Mar 31, 3:17?pm, Helmut Weber wrote:
Danka, Helmut, and hallo to beautiful Bavaria. I'm using a wide-
screen laptop, if that makes any difference. I will try your
suggestion. J

Hi James,

there must be a bug in it.
I got the same message a few times,
then it disappeared.

I never get it in Word.

If the macro is just for you,
you may try it with 1024 or 1200 or whatever.

And it applies to a maximized window.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




Zone

Center Toolbar
 
Helmut, this works fine:
Sub TestCenterJ()
Dim WideScr As Variant
Dim x As Long
Dim v As Long
v = Application.CommandBars("formatting").Width
WideScr = MsgBox("Wide screen?", vbYesNo)
If WideScr = vbYes Then
x = 1325
Else
x = 1024
End If
Application.CommandBars("formatting").Left = x / 2 - v / 2
End Sub
Of course, the problem is the program should be able to automatically
gather this screen horiz center information. Since your
System.HorizontalResolution won't work for me (Excel 2002), I'm at a
loss. Having to ask the user for this info is really embarrassing!
James
On Mar 31, 3:33�pm, "Zone" wrote:
On Mar 31, 3:17?pm, Helmut Weber wrote:
Danka, Helmut, and hallo to beautiful Bavaria. *I'm using a wide-
screen laptop, if that makes any difference. *I will try your
suggestion. *J



Hi James,


there must be a bug in it.
I got the same message a few times,
then it disappeared.


I never get it in Word.


If the macro is just for you,
you may try it with 1024 or 1200 or whatever.


And it applies to a maximized window.


--
Greetings from Bavaria, Germany


Helmut Weber, MVP WordVBA


Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"- Hide quoted text -


- Show quoted text -




Helmut Weber[_2_]

Center Toolbar
 
Hi Zone,

if for professional use:

Option Explicit
Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long

Sub Test()
MsgBox GetSystemMetrics(16)
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Zone

Center Toolbar
 
Helmut, The msgbox displays 1280 on my wide-screen laptop. Would you
happen to know whether this is pixels or points? J
On Mar 31, 4:20?pm, Helmut Weber wrote:
Hi Zone,

if for professional use:

Option Explicit
Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long

Sub Test()
MsgBox GetSystemMetrics(16)
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




Darren Hill[_4_]

Center Toolbar
 
That will be pixels.
Your screen must have a resolution of 1280x800.

Darren
On Sat, 31 Mar 2007 22:06:38 +0100, Zone wrote:

Helmut, The msgbox displays 1280 on my wide-screen laptop. Would you
happen to know whether this is pixels or points? J
On Mar 31, 4:20?pm, Helmut Weber wrote:
Hi Zone,

if for professional use:

Option Explicit
Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long

Sub Test()
MsgBox GetSystemMetrics(16)
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"






--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Zone

Center Toolbar
 
Is there a way to convert pixels into points? Many thanks, James

On Mar 31, 5:18�pm, "Darren Hill"
wrote:
That will be pixels.
Your screen must have a resolution of 1280x800.

Darren





On Sat, 31 Mar 2007 22:06:38 +0100, Zone wrote:
Helmut, The msgbox displays 1280 on my wide-screen laptop. *Would you
happen to know whether this is pixels or points? *J
On Mar 31, 4:20?pm, Helmut Weber wrote:
Hi Zone,


if for professional use:


Option Explicit
Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long


Sub Test()
MsgBox GetSystemMetrics(16)
End Sub


HTH


--
Greetings from Bavaria, Germany


Helmut Weber, MVP WordVBA


Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


--
Using Opera's revolutionary e-mail client:http://www.opera.com/mail/- Hide quoted text -

- Show quoted text -




Helmut Weber[_2_]

Center Toolbar
 
Hi James,

there is more than one bug in this in Excel:

Sub x()
' MsgBox PixelsToPoints(1280) ' error error error
' works perfectly in Word
' or
MsgBox 1280 / 96 * 72 '!
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


Zone

Center Toolbar
 
Guess it's time for me to figure out another strategy. Thanks for the
info.
James

On Mar 31, 7:00?pm, Helmut Weber wrote:
Hi James,

there is more than one bug in this in Excel:

Sub x()
' MsgBox PixelsToPoints(1280) ' error error error
' works perfectly in Word
' or
MsgBox 1280 / 96 * 72 '!
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




Jim Cone

Center Toolbar
 

James,
Centering under the menu bar on my system looks about right...
Sub MakeItHappen()
Dim lngPlace As Long
lngPlace = Application.CommandBars(1).Width / 2
Application.CommandBars("MyCustomBar").Left = _
lngPlace - (Application.CommandBars("MyCustomBar").Width / 2)
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Zone" wrote in message
Guess it's time for me to figure out another strategy.
Thanks for the info.
James


Zone

Center Toolbar
 
Thanks, Jim. Looks pretty good. It is a bit too far to the right on
the widescreen laptop. Who knew just centering a toolbar would be so
difficult? I'll probably go with this solution since at least the
toolbar will always land in the same place, and, in addition to
centering it, I want to be able to show userforms approximately
centered over the icon that calls them. Regards, James

On Mar 31, 10:15�pm, "Jim Cone" wrote:
James,
Centering under the menu bar on my system looks about right...
Sub MakeItHappen()
Dim lngPlace As Long
lngPlace = Application.CommandBars(1).Width / 2
Application.CommandBars("MyCustomBar").Left = _
* *lngPlace - (Application.CommandBars("MyCustomBar").Width / 2)
End Sub
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware

"Zone" wrote in message

Guess it's time for me to figure out another strategy. *
Thanks for the info.
James





All times are GMT +1. The time now is 03:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com