Removing the scroll bar on a list box in Excel VBA UserForms - excel

I'm using a UserForm in Excel VBA and I have a combo box with style fmStyleDropDownList. I want to remove the horizontal scrollbar:
Picture of my combo box with ColumnWidths of 100 pt. The combo box shown has a Width property of 162, a ColumnWidths property of 100 Pt and a ListWidth property of 162 Pt.
Keep in mind that this problem is somewhat similar to this one:
Remove the scroll bar on a list box. In this post, the accepted solution states:
This can occur when you have the column width format property of the listbox set to something wide, then you size the control to the data, it will show the scroll bars.
To fix this, change the "Column Width" property under the format tab to something really small, then play around with this property and the size of the listbox control until you get it how you want, and no scroll bars are displayed.
So what I did is: I changed the ColumnWidths property to smaller values until the horizontal scroll bar disappears. However, this has the side effect that the drop down text has not enough width to be displayed as a whole as it is shown in the following Pictures (the Width and LastWidth property remain at 162):
Picture of my combo box with ColumnWidths of 50 pt. The scroll bar is still there. Instead of "abcdefghijklmn", only "abcdefghijkl" (without mn) is dislayed in the second row of the drop down menu and in the third row it says "something e" instead of "something else". I assume this is because the ColumnWidths property is set too small.
Picture of my Combo box with ColumnWidths of 18 pt. The scroll bar is gone (which is what I want). 18 pt is the biggest value I came up without having a scroll bar. But it now displays only a few (18?) points in any row of the drop down menu which is unacceptable to me.
Any ideas how to solve this?

As Siddharth Rout pointed out, the problem was due to multiple columns. Setting the ColumnCount property back to 1 solves this issue.

Related

How to make a vertical slider?

I need a vertical slider similar the standard slider. Is there a way to modify the existing one or do I need to make a new one?
The standard slider would work for me. I just need it to work vertically.
Perhaps I should better clarify my issue with the standard slider.
Yes, I can drag the size of the slider and it will be vertical. The problem is that when you select the value of the slider to show the text gets buried in the low side of the slider when you slide it down all the way. It essentially gets cut off and only shows the top half of the slider value character. I find no way to correct this by moving the shown text up a little so it all shows. I see no way to change text vertical or offset position in the properties setting.
The text settings only allow you to change the text format to right, center and left justify. There is no setting that can move the text up to prevent it from being cut off when the slider is all the way to the lower or down position.
The value text shows ok on the top of the slider. The problem is on the bottom side when you set the slider to be vertical.
It looks like the the show value setting does not place the value on the top layer of the slider and it gets hidden behind something else in the slider object.
LC9, Windows 10
I think I'm understanding your question. If you just resize the horizontal slider control so that the width is narrower than the height, the orientation of the slider control will automatically change to vertical.
Apparently it is a bug in this version of LC. At least in Win which is where I am testing.
Putting the scrollbar vertically cuts the value when it reaches the bottom.
But I found a solution so that it does not cut. Play around with the properties of the font. Such as size and family. In my case it worked fine by lowering the font size by one pixel.
Default: Segoe UI font, size 12
I just set the size to 11 and it doesn't cut anymore.
For what it is worth, I do not see this issue on a Mac. A vertical slider works as advertised. Font size makes no difference.
Are you saying that in the horizontal mode, you do not see this, but when changed to vertical, you do?
Try creating a scrollbar and a text field.
Set the scrollbar's showValue property to false and copy the following script to your scrollbar. Note that your field must be called "scroll value".
on scrollbarDrag pNewPosition
local tLoc
lock screen
# The Current Loc of Field
put the loc of field "scroll value" into tLoc
# New Position of scrollbar
put pNewPosition into field "scroll value"
# New Loc of Field
put the mouseV into the item 2 of tLoc
set the loc of field "scroll value" to tLoc
set the left of field "scroll value" to the right of me
unlock screen
end scrollbarDrag

Adjust listbox to display string longer than listbox width using Excel VBA

In my listbox the strings are longer than the listbox width.
I cannot change the listbox width because of the already made up surface design:
Is there a VBA property for the listbox to:
break the string in half and display it on more than one line
or
scroll horizontally, to see the whole string
If there's not that kind of property, I'd like to know of other ideas.
The ListBox is single line only and does not support line breaks.
If it is an ActiveX then it has a property called ColumnWidths. Set it to something bigger like 500 and you will see a scrollbar at the bottom of the ListBox.

Determine Visible Worksheet Area Size in Points

I am trying to determine the visible worksheet area in points. So far, I have tried the Application.Width, but that gives me the entire area including the scroll bars, and likewise Application.Height includes the ribbon and horizontal scroll bar. What I need specifically is the size of only this viewable worksheet area.
Something I have tried so far is looking at the visible range. For example, if I can see A1 thru AA40, then I can use the code
Debug.Print ws.Range("A1:AA40").Width
Debug.Print ws.Range("A1:AA40").Height
The only problem with this is if I can see half of column AB and half of row 41, then I don't have the full size. Also, it is not adjustable if I decide to change the application window size to half the screen.
I have no need for converting into the number of pixels, I just need the point sizes. Does anyone know a way to get the visible area size, or at the very least how to resize a range to fit only this visible area?
You can access the Windows collection of Application and use the Width and Height properties of items of that collection. E.g.
Debug.Print Application.Windows(1).Width
Debug.Print Application.Windows(1).Height
You can also refer to ActiveWindow and get the properties from that as well.
Example:
Grid's dimensions:
?Activewindow.activepane.VisibleRange.Height, Activewindow.activepane.VisibleRange.Width
The above worked for me, returning the dimensions of only Excel's grid which could be seen on my screen- no scrollbars, no Ribbon, no formula bar - just cells displayed.

how to prevent vertical scroll bar in an owner drawn combo box when only 3 items exists?

I sub-classed a combo-box control to make text vertically centred. Issue here is I am getting a vertical scroll bar when only 3 or 4 items exists in the combo-box that too when I expand the control for the first time, where a vertical scroll is not required.
Control property had been set as follows.
COMBOBOX IDC_COMBOBOX,28,45,205,65,CBS_DROPDOWNLIST | CBS_OWNERDRAWNFIXED | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP.
When I removed WS_VSCROLL vertical scroll bar is not coming. But if I remove this property I will not get a scroll bar when too many items exists in the combobox, where actually a scroll is required.
Please find the below Images for your reference how the control is behaving.
Run the MFC application.
Expand the combobox.
Again try expanding the combo box issue is not reproducing. It's happening only
for the very first time when expand the control.
I could not figure out why this issue is happening. I tried removing the existing control and again I tried adding new controls expecting whether it could bring any change in the behaviour but no luck.
Item height is set to 30 as below.
m_ComboBox.SetItemHeight(-1, 30);
And I had two combobox controls in my properysheet application as shown in the image.
Any help is appreciated.

Why is Autofit Labeling greyed out?

I Have created a bar chart in a 2007 .xls file, but the data labels cannot be resized. When you go to the "format Data Labels" and then click on alignment, the Autofit and Internal Margin option is grayed out. Anyone know why?
Short version: It is greyed out for chart text, because it the option doesn’t apply.
Long version:
This is because on a chart, chart text do need to use margins, rather you can you can just move the text., and set its X and Y position. For example take the Chart Title, if you want more space to the left, just click and drag the title to the right. If you want the chart title to be bigger you just set a larger font, you have complete control over the title, as well as all other text on that chart, axis titles, legends, data labels, etc.
Internal margins are meant to be used when you don’t have complete control take for example text in a shape. If you insert a shape in your workbook, and add text to it, you cannot just pick the text up and move it to the right if you want more space on the left, so you can set the margin.
Here's a trick that worked for me:
My problem was: I added more text to the axis title and it was too long for it's original shape so some text went into second line.
My solution: I type the complete text somewhere else, copy the text, double click on the axis title and delete the original text -- the cursor would still be there -- now insert the copied text. Done! They are all in one line!
Partial solution to resize label to a single line: Data labels in a chart will often wrap themselves, when you dont want them to. They would often seem better in a vertical single line above the graph item. Reset them to one single line by editing the text in the label, deleting the Excel imposed return, and replace it with a space. The line, and label box, will resize to fit a single line. However because you have "manually interfered with the lable, it will no longer update for changing graph data. You would have to double click each lable then reset it. Most annoying.
A way around it is to make the chart area big. The data label boxes will resize to fit the words in one line. Then make the chart small (not the chart area).
Manually insert a textbox into the bar chart and type in the label that way. It's annoying and labor-intensive, but it works.

Resources