hide name box

T

T. Valko

Anyone know how to hide (not display) the name box *but still* display the
formula bar?
 
J

Jim Cone

Biff,
All the code I can remember seeing is aimed at widening the name box.
But that implies that it should be possible to make it smaller (zero?).
I tried the following code when the first version appeared,
maybe in 2000, but had, uhh, some stability problems...
http://www.vbrad.com/article.aspx?id=75
I believe also that Chip Pearson has some code on his site to widen the box.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"T. Valko"
wrote in message
Anyone know how to hide (not display) the name box *but still* display the
formula bar?
 
R

Rick Rothstein \(MVP - VB\)

Anyone know how to hide (not display) the name box *but still* display
the formula bar?

How about if we leave it displayed, but clear the edit field and then
disable it? Add a Module and copy/paste all the code after my signature into
its code window. To use it, simply execute this code...

To disable Name Box: EnableNameComboBox False

To re-enable Name Box: EnableNameComboBox True

Note: I have cobbled this together from many different sources. I have left
in (or expanded on) the comments that were included with the original code
in case you want to "tinker" with the code some.

Rick

' Enables or disables a window. If a window is disabled, it cannot
' receive the focus and will ignore any attempted input. Some types
' of windows, such as buttons and other controls, will appear grayed
' when disabled, although any window can be enabled or disabled. The
' function returns 0 if the window had previously been enabled, or a
' non-zero value if the window had been disabled.
Private Declare Function EnableWindow Lib "user32.dll" _
(ByVal hwnd As Long, _
ByVal fEnable As Long) As Long

' Get the handle of the desktop window
Private Declare Function GetDesktopWindow Lib "user32" () As Long

' Get the process ID of this instance of Excel
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long

' Get the ID of the process that a window belongs to
Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, _
ByRef lpdwProcessId As Long) As Long

Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Private Const WM_SETTEXT As Long = 12&

'Make the Name dropdown list 200 pixels wide
Public Sub EnableNameComboBox(State As Boolean)
Dim hWndFormulaBar As Long
Dim hWndNameCombo As Long
'Get the handle for the formula bar window
hWndFormulaBar = FindWindowEx(ApphWnd(), 0, "EXCEL;", vbNullString)
'Get the handle for the Name combobox
hWndNameCombo = FindWindowEx(hWndFormulaBar, 0, "combobox", vbNullString)
' Clear the NAME box's edit field
SendMessage hWndNameCombo, WM_SETTEXT, ByVal 0, ByVal ""
' Disable the NAME box
EnableWindow hWndNameCombo, State
End Sub

' Get the main Excel window's hWnd
Private Function ApphWnd() As Long
'Excel 2002 and above have a property for the hWnd
If Val(Application.Version) >= 10 Then
ApphWnd = Application.hwnd
Else
ApphWnd = FindOurWindow("XLMAIN", Application.Caption)
End If
End Function

' Finds a top-level window of the given class and caption that
' belongs to this instance of Excel, by matching the process IDs
Private Function FindOurWindow(Optional sClass As String = vbNullString, _
Optional sCaption As String = vbNullString)
Dim hWndDesktop As Long
Dim hwnd As Long
Dim hProcThis As Long
Dim hProcWindow As Long
'Get the ID of this instance of Excel, to match to
hProcThis = GetCurrentProcessId
' All top-level windows are children of the desktop,
' so get that handle first
hWndDesktop = GetDesktopWindow
Do
' Find the next child window of the desktop that matches the given
' window class and/or caption. The first time in, hWnd will be zero,
' so we'll get the first matching window. Each call will pass the
' handle of the window we found the last time, thereby getting the
' next one (if any)
hwnd = FindWindowEx(hWndDesktop, hwnd, sClass, sCaption)
' Get the ID of the process that owns the window
GetWindowThreadProcessId hwnd, hProcWindow
' Loop until the window's process matches this process,
' or we didn't find a window
Loop Until hProcWindow = hProcThis Or hwnd = 0
' Return the handle we found
FindOurWindow = hwnd
End Function
 
T

T. Valko

Hi Jim!

You pretty much have the same thought process as I do.

I've seen requests to widen the box so you'd think that there should be a
way to set it to 0 width.
stability problems...

Yuck!

I'll try that add-in and also see what Chip has.

Thanks!
 
T

T. Valko

I pretty much figured that but hoped there was some way to manipulate it
since it can be widened.
 
T

T. Valko

Hi Rick!

Well, that's not what I had in mind but thanks for the time and effort.
 
R

Rick Rothstein \(MVP - VB\)

I realize this was not what you were looking for, but given your other
responses indicating that what you wanted was probably not possible, I
figured disabling the control was probably the closest you would be able to
come to what you asked for. As for the time and effort... well, I considered
the formulating of a plan of attack for your question, and then finding out
how to implement that plan, a fun thing to do. I'm sure, as a volunteer here
in these newsgroups, you get the same type of enjoyment in solving the
out-of-the-ordinary problems as I do.

Rick
 
T

T. Valko

I'm sure, as a volunteer here in these newsgroups, you get the same type of
enjoyment in solving the out-of-the-ordinary problems as I do.

Yes, absolutely!
 
R

Rick Rothstein \(MVP - VB\)

I knew it!

So anyway, what is it you are trying to do that hiding the Name Box is the
only answer? Since a disabled Name Box is not an acceptable solution, would
a gap in its place on the formula bar be an acceptable one? I am just
curious as I have another idea I will try to pursue later on, but I don't
hold out much hope for it working.

Rick
 
T

T. Valko

I'm working on a project that uses lots and lots of screencaps.

I can make these caps smaller width-wise if I can get rid of the name box
*but* I still want to display the formula bar so I can show formulas in
their cells. Resizing the screencap beyond a certain point in order to get
the right size for the project makes it harder to read. So, in most cases
getting rid of the name box gives me more room (size of screencap) without
having to resize it and making it harder to read.

P.S. - I'm using a good quality capture tool - SnagIt
 
R

Rick Rothstein \(MVP - VB\)

I'm afraid you lost me. I'm guessing from your SnagIt reference that
"screencaps" are "screen captures". If that is the case, then I don't
understand your reference to resizing them or why getting rid of the Name
Box makes it easier to read them... I am just having a hard time visualizing
what you are doing. In any event, it sounds like getting rid of the Name
Box, but leaving a blank area where it, was would not be a solution for you
either (so much for that other idea I had<g>). Maybe once I can visualize
what you are doing, I might come up with another idea.

Rick
 
J

Jim Cone

Biff,
For what it's worth...
I've read several positive comments about SnagIt, but have never used it.
I have developed a fondness for FastStone Capture. I used it to
grab and refine the "illustrations" that I have just added to my website.
It includes a tool to do a screen capture of what ever you encircle with
the freehand arrow. It can slap the captured pictures in its editor where
you can crop | resize and do other stuff and then automatically save them.
As I said, for what it is worth.
--
Regards,
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"T. Valko"
wrote in message
I'm working on a project that uses lots and lots of screencaps.

I can make these caps smaller width-wise if I can get rid of the name box
*but* I still want to display the formula bar so I can show formulas in
their cells. Resizing the screencap beyond a certain point in order to get
the right size for the project makes it harder to read. So, in most cases
getting rid of the name box gives me more room (size of screencap) without
having to resize it and making it harder to read.

P.S. - I'm using a good quality capture tool - SnagIt
 
T

T. Valko

Ok, try to visualizie this.

This is what the default formula bar looks like:

| Name box | Insert Function | Formula bar |

Now, imagine that the name box is not on the formula bar. So, you would
think that the actual part of the formula bar that displays the cell
contents would be further to the left.

| Name box | Insert Function | Formula bar |
| Insert Function | Formula bar |

With the name box displayed screencaps (screen captures) are wider taking up
more space even after trimming off (cropping) any unused space. Resizing
shrinks the size of the text making them harder to read.

Without the name box there's either no need to resize or, I can resize less
thereby not affecting the readability.

If this can't be done (at all) or without major effort then I'll just have
to "suck-it-up".
 
T

T. Valko

Well Duh!

Sometimes I'm a complete idiot! (but you don't have to agree!) <g>

Excel 2007 has this capability but I was working in (and prefer) Excel 2002.

This will push me to start using Excel 2007 as my default application (even
though I'm not "diggin" it).

Thanks to everyone for their input.
 
R

Rick Rothstein \(MVP - VB\)

'Make the Name dropdown list 200 pixels wide
Public Sub EnableNameComboBox(State As Boolean)
........

By way of clarification, that comment block was left over from the routine I
used as a basis for the changes I made in order to create an enable/disable
routine for the Name Box... I should have changed it, but forgot to do so.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top