Missing Properties in VBA [duplicate] - excel

I'd like to add a horizontal scrollbar to a VBA ListBox.
It appears that the built in ListBox does not add a horizontal scrollbar automatically. I have a number of fields whose contents exceed the width of the ListBox and are thus unreadable to the user.
I found this article, however the code fails, due to accessing hwnd of the ListBox (which is apparently not available in VBA). I'd rather not write a native DLL to accomplish this as I suspect there is a better way.
Any idea on how I can add a horizontal scrollbar to a VBA ListBox?
I'm open to the idea of using an alternate control rather than getting it to work with the ListBox specifically.

Did you try ColumnWidths property?
I have listbox with horizontal scroll bar. I just had to add ColumnWidths property.
For example I have
me.Listbox1.Columnwidts ="0.5 in;0.2 in;1.5 in;0.75 in;0.5 in"

Unless I'm missing something, a VBA listbox will automatically gain a horizontal scrollbar if the total of its ColumnWidths property exceeds its own width.
There are no properties I know of that affect this behaviour, i.e. I don't otherwise know how to force or disable display of the horizontal scrollbar.

Access will automatically add a horizontal scrollbar if the column width exceed the width of the listbox. HOWEVER, if you are using multiple columns, the first column cannot be set to 0. You must have at least some value in there, even if it's just 0.1" Hope this helps.

In that article, the only reason it's getting ScaleMode is to set the width of the horizontal scroll bar. You don't have to do that.
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, 800, 0
where 800 is the pixel width you want the list box to be able to scroll right to.
You will still need the hWnd. Best bet there is to use an external DLL (written in VB) which can enum through child windows of your process until it finds the windows class for the listbox (you will need to find some way to uniquely identify its parent, such as the window title/text or something). That same DLL could also do the SendMessage call above to set the horizontal text extent (perhaps also it could measure the width of the contained list items).

Handle to he list box can be obtained as follows :-
Dim ListHwnd As Integer
lstboxName.SetFocus
ListHwnd = GetFocus()
Use this ListHwnd as the first parameter to the sendmessage function...
We need to provide the declaration below,Since GetFocus function is not present in VBA by default
Private Declare Function GetFocus Lib "user32" () As Integer

In Visual Studio 2017, you can click on the list box, then go to the properties panel, and then (scroll down to) find the 'HorizontailScrollbar' property. By default this is property is set to false, so you should set it to true.
You know you have set the scroll bar properly when a small triangle appears in the top right corner of the list box.
Hope this helps.

Related

Excel - how to hide value in a chart's datalebel

I have embedded an image to a chart's datalabel. I want to only keep the image and not the value which appears on top of the image.
However I'm not sure how i can get rid of the value to only show the image?
I thought could've set the font colour to transparent but that's not available. I also played around with the number formatter but had no luck?
I'm using Windows/Excel 2010
Thanks
Clicking on one of the data labels once will select all of them, clicking a second time will select only the one you clicked on. Then just hit the delete button. (You should also be able to edit the font/colour in the Home tab.)

How do I allow user to select, but not edit, text in an excel userform control whose width is smaller than the text?

Context
I want the user to review some selections they made earlier. So I display some text describing each selection on a separate control in a userform. Some of the text on the controls is long, extending beyond the width of the control. This is fine; I just want the user to be able to see all of the text without being able to edit it. To do this, I use textboxes that are "Locked" (i.e. not editable) but "Enabled" (i.e. selectable). This way, they can just click and either mouse-drag or arrow-key over to scroll through all the text.
Problem
The (small, aesthetic) problem is that when the user clicks in one of the textboxes, they get a blinking cursor, which is misleading as that is normally associated with an editable textbox.
Possible solutions
Ideally, there would be some way of removing the blinking cursor, while still allowing selection but not edition. However, I'm open to other alternatives that don't have to do with changing the width, or having a scrollbar (the textbox is too short to fit a scrollbar). The best alternative I have so far is changing the background color to a gray to make it slightly more clear that it's not editable.
P.S. I'm very familiar with VBA, so if that's part of the solution, I'm cool with that.
Thanks all!
I had a similar issue, and solved it by using these instructions to create a hidden textbox that the cursor automatically appeared in (invisible to the user).

TableWrapData: widgets won't left align properly

My program uses TableWrapLayout with numColumns set to 2. I then have the following code: (background colors are set to show you that the widgets aren't using the blank space).
Label label = toolkit.createLabel(container, "Resource Type":);
label.setLayoutData(new TableWrapData(TableWrapData.LEFT,TableWrapData.MIDDLE));
label.setBackground(DiagramSettings.NODE_BACKGROUND_COLOR);
resourceComboMenu = new Combo(container, SWT.READ_ONLY);
resourceComboMenu.setBackground(DiagramSettings.NODE_BACKGROUND_COLOR);
resourceComboMenu.setLayoutData(new TableWrapData(TableWrapData.LEFT,TableWrapData.MIDDLE));
However as you can see in the picture the combo box refuses to left align properly. But that I mean I want it to start right after the label, not have a bunch of blank space.
One workaround would be to put the row inside it's own Composite just like I do Resource Icon and Geolocation. But I feel like I shouldn't need to since the widgets on this row equals the number of columns set by the layout. I've created this workaround for now but would like to understand this TableWrapData behavior for the future.
Any insight would be helpful, thanks.
I pretty much answered my question in the question. The composite that contains everything in the picture had TableWrapData with columns set to 2. TableWrapData essentially draws a straight, vertical line between each column then makes sure widgets from one column don't cross it.
So to fix this (like I mentioned in my question) you simply make another composite with nested widgets (which in the case would be the resource type label and resourceComboMenu). I just didn't realize that is what you're supposed to do.

Combobox not displaying the data items

I have been trying to add Data items for my combobox in the DialogWindow of my mfc project, at design time by setting strings delimited by semi-colons for the Data property of this combobox.
But it just shows empty combobox at runtime. I tried using AddString() method of this combobox manually in the OnInitDialog() event of the DialogBox too. But that was also not working.
Tried creating a demo project again and when I added the combobox and put the value a;b in the Data property of it, it is showing up. But tried the same on my project and it is still showing the empty list in the new combobox! Tried to compare both project's code, like the header files and initialization's etc. Found that both are same. Other than some event declaration for the buttons and my custom c++ code in my project, the rest of the code is same as that of the newly created demo project!
Why in my project this combobox is showing an empty list of items? :(
EDIT:
Just noticed that the items are already in the list. But the dropdown is of small height and thus preventing the actual items from showing up! :(
Tried to look increasing the size of the combobox, but I couldn't find any property in the Property Window and dragging the corners of th combobox doesn't increases the height either! :(
Increase the size of the dropdown list like this, in the design window:
Click on the arrow on the right side of the combobox (highlighted in yellow on first pic). Then click and drag the bottom mid resize marker to increase the height (highlighted in the second pic).
This will increase the size of the dropdown list.
Otherwise when we try to click on the resize markers to increase the height, it would be disabled. So make sure you click on the arrow on the right side of the combobox first.

Bug with Excel form control - scrollbar keeps scrolling

I'm creating a dynamic chart using an Excel form control -- the scrollbar -- and the way this works is exactly as described on http://www.excelcharts.com/blog/animation-interaction-and-dynamic-excel-charts/ (towards the bottom). I have a chart of data, and a column called "Chart source" that just does an index match based on the scrollbar's linked number. When you click through the scrollbar, it updates the chart source column and thus the chart.
The problem I'm having is that when I click the scrollbar, it keeps scrolling all the way, to either the left or the right, instead of moving incrementally one by one. The number counts through 1 by 1, but it goes all the way as if I were continuously clicking the button. This behavior stops in its tracks if I click and then move the mouse out of the arrow area. I've tried messing with the form control's "incremental change" and "page change" options to no avail. Things that do work: I can click and drag the scrollbar itself to the place I want it. I can type a new number in the cell linked to the scrollbar, and the scrollbar will jump to the right position.
Does anyone have an idea of how to fix this bug?
EDIT: I figured out the problem. This is a bug in Excel. If you are in "Page Break Preview" mode instead of "Normal" mode, this behavior will happen. Switching back to "Normal" mode (the first of the three icons in the bottom right next to the zoom) fixes this behavior.
This problem occurs when calculations that result from the changed value that is controlled by the scroll bar, takes too long. Changing to Manual calculation mode resolves the problem (although of course is not necessarily desirable in all cases)...
(see http://www.pcreview.co.uk/forums/slider-bar-continues-increment-mouse-hovers-over-arrow-t3064239.html)
The same has been happening to me, but my excel sheet was in "normal" mode.I believe the original answer is correct. I noticed this happens when I press a combination of keys or my hand lightly brushes across bottom pf laptop. Very annoying. Finally I sit and wait for the scrolling to stop then click back to top of sheet.
Possible answer... I have the problem with one type of worksheet, but only when another worksheet with VBA code is open. A fix might be, in the first worksheet:
File\Options\Advanced\Formulas\un-check Enable Multi-Threaded Calculation
I figured out the problem. This is a bug in Excel. If you are in "Page Break Preview" mode instead of "Normal" mode, this behavior will happen. Switching back to "Normal" mode (the first of the three icons in the bottom right next to the zoom)

Resources