I'm having a very strange issue with Excel UserForms; when I display a form by clicking a command button in my worksheet, the size of the form warps significantly, making it essentially unusable. The below images illustrate this.
Form before size warping (intended size)
Form after size warping
I work with a multiple screen setup, and this sizing issue only occurred at first when just using my laptop without the additional displays; however, it has now started occurring even with my usual setup. Furthermore, in some cases, the warping compounds with each subsequent form initialization. I've included example images of this below.
Form before warping (intended size)
Form after warping (first iteration)
Compounded warping (second iteration)
Further compounded warping (third iteration)
I've tried setting the height and width properties manually, both through the properties window and through the Userform_Initialize() event, but still end up with strange results. In the properties window, the values I enter for height and width are automatically changed after I enter them, usually resulting in undesirable aspect ratios, and a similar thing happens when I try to resize with VBA. I don't think the code is the issue, as I'm simply setting the .Height and .Width properties so there isn't much room for error.
I've done relatively extensive research and haven't been able to find any information about this issue. I'm using Excel 2016; any help would be appreciated!
I think your issue might be related to mine here.
#Lance Phillips: the option you are referring to (image below found on the web) is missing on my side with Excel 2016 32-bit Windows 10 64-bit. I have no idea why. Even with an extra monitor connected.
Edit: apparently this is a new feature from Office build 9330.1000, see here.
This is a new issue that is occurring in Excel. I have seen it my applications too. In Excel General Options, set to "optimize for compatibility" and the issue should go away.
Other users may not know to set the compatibility mode. If the spreadsheet will be shared with multiple users, use this code to set the correct form size every time it is opened.
Private Sub UserForm_Initialize()
'
' Initialize frm
' (This runs everytime the form is opened)
' frm is the form name
'
' Reset the size
With frm
' Set the form size
Height = {enter desired form height}
Width = {enter desired form width}
End With
End Sub
Check your magnification settings in Windows (Ease of Access). It completely threw my forms sizes. Some were large, others small. Font sizes were as your examples. When a form was created, it inherited the Windows magnification.
Related
I have a simple excel form with an ActiveX control (ListBox)
When I share this over email, the recipient does the following steps:
1. Open the excel
2. Enable Content for the macro
Now - the ListBox grows in size.
I'm unable to dynamically resize or figure out the exact event for "Enable Content".
Is there anyway I can retain the dimensions of the ListBox?
Your problem has nothing to do with sharing the document via email. It has everything to do with window scaling. To prove this to yourself try connecting to a projector with the the excel document open. Use some Active X controls and they will shrink or Expand. I've had this problem and found the only way to avoid it in a reasonable manor is to implant a form inside the excel document that holds all the needed controls or ensure the end user is not scaling their display in any manor.
If I run my program this is what I see
That's not the size of the form that I make. It seems that when I click run, windows set the size of the form as the size of any standard form that shows up.
The size of the form is similar to the size of a newly opened internet explorer.
If I set the form to be unresizeable the form is indeed unresizeable but it's initial size is determined by windows.
How do I set that the size of the form match the size of the form when I design the program?
You need to check a couple of properties of the form as a combination of these may affect the form size such as AutoScale, AutoSize, FormBorderStyle, WindowState. Also check for the DefaultSize, Size, Width, Height, MaximizedBounds and ClientSize properties.
You should also check the form events, particularly Load event, whether you are setting any of those properties in these events?
As another approach you can try fixing the form size in the Load event.
Assuming that you are using WinForms, try setting the form's StartPosition property to WindowsDefaultLocation, CenterScreen or Manual.
Hi so I have just noticed something very strange and I'm wondering if anyone else has had this issue and how to fix it.
Basically using visual studios 2010 on a windows 7 computer I have noticed that the locations of my controls on a form are out of sync with the form size itself.
For example: If I make a form and set its size to 500x500 and then place a control on the form like a button and set its size to the same and its location to 0,0 then the control is cut off by about 10 pixels or so. It happens on both my work and home computer so it isn't the computer and the values are the same at both runtime and design time. It seems as though the controls are being scaled differently than the form and I am not sure why.
Any ideas?
The form's size includes the border. Use the ClientSize property instead.
Looking for a free spell checking solution, I thought I was so smart in doing this but I guess not.
I have created a windows form based application and I want the form to add a user specified amount of user controls (with textboxes) on to a panel. The user can then click some button and the controls on this panel are cleared and new ones are added. The user does something and the process is repeated. Now, I wanted these textboxes to support spell checking and looked all over for a free solution.
WPF textboxes support spell checking where the ones in regular win forms do not. I thought I would be able to use these WPF textboxes by adding them to an ElementHost object which is, in turn, within a panel. This panel would be a user control.
So, in my application, I would be able to add instances of these user controls onto the form and make use of .NET's spell checking goodness. This actually worked but after using the application for a while, found that the application would eventually freeze on me due to out of memory errors. I have pinpointed the memory errors to these WPF controls since this problem does not happen with normal textboxes.
When the window is opened and the number of controls is specified, this is pretty much how the controls are added:
Dim xOffset As Integer = 0
For i As Integer = 0 To theNumber
Dim myUserControl As New SpecialUserControl()
myPanel.Controls.Add(myUserControl)
myUserControl.Location = New Point(7, 7)
myUserControl.Location = New Point(xOffset, 7)
xOffset = xOffset + 207
Next
Note that:
myPanel is a panel on a form
SpecialUserControl is the user control with WPF textbox (within an ElementHost object)
When the user pressed a button, the panel is cleared:
myUserControl.Controls.Clear()
The user can then repeat the process.
There are a lot of results on the internet when I tried to find a solution and I'm thinking that the problem I am having is due to the fact that the WPF control is not going away even after clearing the panel. Following this conclusion, I have tried different solutions regarding disposing these controls or setting them to nothing but the memory problem keeps occurring. If someone could give me some advice or ideas here, I'd really appreciate it.
I've decided that this may just be due to the fact that these user controls are being created faster than they can be collected. I've changed the program so that it doesn't create any of these special user controls if it isn't necessary. The program works fine with a more manageable number of WPF controls.
I am working on a Word VBA macro app for 80 or so users. The office has high staff turnover, so training suffers, and so one of the self imposed requirements for this project is comprehensive, friendly documentation. However, to supplement this, and to save newbies having to open up a 100 page document when they want to try something new, I want a status bar on every userform (there are five) that provides contextual help. I find tooltips annoying.
I don't have a lot of experience, so I was wanting to
Essentially, I have a file containing every status string. (This is currently a text file, but I was wondering if I should use a spreadsheet or csv for ease of editing by other staff in future.) Every control has a MouseMove event which refers to a function: getStatus(cID) that opens the file, grabs the line and displays it in the status label. It also grabs a few parameters from the same line in the file, such as whether the label is clickable (to link to a page in the help file), and what colour the label should be.
So a few questions really:
Will the application be slow if a userform is constantly referring to a file? It feels fine to me, but I've been in it far too long, and I'm the only user accessing that file. There will be 80 constantly accessing it.
Is MouseMove over a control the best way? Should I instead use co-ordinates?
Most importantly (in terms of me having to do as little work as possible) is there some way to do this so that I do not have to have a MouseMove event on every single control? I have a good few hundred or so controls, each with their own identifier (well, not yet, but they will if this is the only way to do it). Maybe when the form loads I could load ALL the possible status lines so they're ready for whenever the control is moused over. But then, maybe the loading time is negligible?
Appreciate any ideas or thoughts - especially if VBA already has a whole range of functions to do this already and I'm just trying to reinvent the wheel. I can't use the application status bar, because the user rarely sees the application itself.
Thanks!
EDIT:
It is for both data entry, clicking around and a bit of document generation.
It is a controlled environment so macro security issues aren't a big concern for me - and if something goes wrong it's someone else's fault or problem :)
Is this data entry app or do they just click stuff? Because often the field with focus is different to the item the mouse is hovering over, this can cause a lot of confusion.
Constantly reading from a file is a huge waste of time and resources - it is much better to load them only once into an array or collection when the form is loaded.
On MouseMouse event is better than coordinates because you can move things around without worrying. It's a lot of code but you should be able to generate most of that if you have a list of control names because the code should be identical.
ie
Sub Control_MouseMove()
DisplayStatus(Control)
End sub
I would consider the StatusText property and ControlTipText property of controls for this kind of help.
StatusText
This example sets the status bar help text for the form field named "Age."
With ActiveDocument.FormFields("Age")
.OwnStatus = True
.StatusText = "Type your current age."
End With
ControlTipText
This can be assigned from the property sheet for the control.
Private Sub UserForm_Initialize()
MultiPage1.Page1.ControlTipText = "Here in page 1"
MultiPage1.Page2.ControlTipText = "Now in page 2"
CommandButton1.ControlTipText = "And now here's"
CommandButton2.ControlTipText = "a tip from"
CommandButton3.ControlTipText = "your controls!"
End Sub