Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Using ShowScrollBar API call in VBA?

I'm in a situation where I need to use the VBA Listbox control to show 1 piece of data per row, but store 3 pieces of data. After a futile attempt at trying to attach a custom object to each list item, I'm now attempting to use 3 columns, but hiding column 2-3, by making column 1 as wide as the listbox and hiding the horizontal scrollbar that appears.

I found an API function for this, but VBA complains about the nonexisting .hwnd property.

Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long

Private Const SB_HORZ = 0 ' Horizontal Scrollbar
Private Const SB_VERT = 1 ' Vertical Scrollbbar
Private Const SB_BOTH = 3 ' Both ScrollBars

....

ShowScrollBar Listbox1.hwnd, SB_HORZ, False

Any ideas?

Gustaf
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Using ShowScrollBar API call in VBA?

Nevermind, I found a cleaner solution. Column 2-3 can also be hidden by setting their width to 0 in ColumnWidths (the property holds a semicolon-separated list of pixel widths). Hope it helps someone. :-)

Gustaf

--

Gustaf wrote:
I'm in a situation where I need to use the VBA Listbox control to show 1
piece of data per row, but store 3 pieces of data. After a futile
attempt at trying to attach a custom object to each list item, I'm now
attempting to use 3 columns, but hiding column 2-3, by making column 1
as wide as the listbox and hiding the horizontal scrollbar that appears.

I found an API function for this, but VBA complains about the
nonexisting .hwnd property.

Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long,
ByVal wBar As Long, ByVal bShow As Long) As Long

Private Const SB_HORZ = 0 ' Horizontal Scrollbar
Private Const SB_VERT = 1 ' Vertical Scrollbbar
Private Const SB_BOTH = 3 ' Both ScrollBars

...

ShowScrollBar Listbox1.hwnd, SB_HORZ, False

Any ideas?

Gustaf

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Using ShowScrollBar API call in VBA?

re listbox
set column count to 3
set column widths to ;0;0
which will hide columns 2 & 3

now either set the rowsource to 3 columns eg A5:C15

or code the population

Dim cell As Range
Set cell = Range("A1")
Do Until cell = ""
With ListBox1
.AddItem cell.Value ' column 1 (0 base)
.List(.ListCount - 1, 1) = cell.Offset(, 1).Value ' column 2
.List(.ListCount - 1, 2) = cell.Offset(, 2).Value ' column 3
End With
Set cell = cell.Offset(1)
Loop





"Gustaf" wrote:

I'm in a situation where I need to use the VBA Listbox control to show 1 piece of data per row, but store 3 pieces of data. After a futile attempt at trying to attach a custom object to each list item, I'm now attempting to use 3 columns, but hiding column 2-3, by making column 1 as wide as the listbox and hiding the horizontal scrollbar that appears.

I found an API function for this, but VBA complains about the nonexisting .hwnd property.

Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long

Private Const SB_HORZ = 0 ' Horizontal Scrollbar
Private Const SB_VERT = 1 ' Vertical Scrollbbar
Private Const SB_BOTH = 3 ' Both ScrollBars

....

ShowScrollBar Listbox1.hwnd, SB_HORZ, False

Any ideas?

Gustaf

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
Wouldn't know what to call it! 1Fish2Fish Excel Worksheet Functions 5 August 26th 08 07:37 PM
How to call this DLL? Paul Lenz Excel Programming 0 September 9th 07 08:12 PM
I'm not sure what you'd call it, but is it possible to do this? nut_mom Excel Discussion (Misc queries) 3 June 28th 06 06:17 PM
Call Center Management: How to calculate 'cost per call' Denniso6 Excel Discussion (Misc queries) 2 June 25th 06 05:01 PM
How do you call one Sub from another Sub ? lothario[_30_] Excel Programming 2 October 17th 03 01:47 PM


All times are GMT +1. The time now is 08:17 PM.

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"