VBA Active-X buttons getting bigger with every action - vba

I have an Excel sheet containing multiple Active-X buttons. Whenever I click on a button/perform an action, the buttons will keep getting bigger with every action.
Initially this didn't happen at my desk (laptop in dock with two big screens), but when I moved and used the program just on my laptop, it suddenly started happening. The only fix I found is to hard-wire the positions right in the code. I feel that there has to be a solution.
Below is a sample of my code.
Private Sub SpinButton1_SpinDown()
Dim myCell As Range
Dim myRange As Range
Set myRange = Selection
SpinButton1.Height = 45
SpinButton1.Width = 39
SpinButton1.Left = 283.5
SpinButton1.Top = 328.5
For Each myCell In myRange
myCell.Value = myCell.Value - 1
Next myCell
End Sub

It is a Microsoft bug in some versions of Office. Not 100% sure if your version is affected, but you can check here: http://support.microsoft.com/kb/2598259
The fix is also available for download from there.
Also, it is not advisable to use ActiveX buttons unless you want to make colorful buttons with fancy decorations. Even then you can replicate the same effect using
Images which look like the buttons you want (with shadows and all for the 3D effect)
Setting MouseOver tooltips for the correct look and field for buttons
Assigning Macros for Click-behavior, etc.

I have this same issue. It is very sporadic. I have two Excel workbooks with similar buttons on each. This only happens on one of them, but it happens every time I open it. I have found a sort of work-around. I open a blank Excel document, then I open the affected one and the buttons do not change size any more. When I open the second one, I have to drag it into the window with the already-open file. If I double-click on it, it opens in a new window and the problem remains.

Related

Copying the content of multiple UserForm textboxes to clipboard

I built a Microsoft Word template with a userform containing textboxes. I want to copy the data of two textboxes into the clipboard separately upon submitting the completed userform. Just to clarify I want each textbox to have its own entry into the clipboard for easy access in the future.
Below is the code I'm using but when I repeat the procedure it replaces the first textbox in the clipboard with the second. Any help would be greatly appreciated.
Sub ComandButton_click()
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText Me.TextBox1.value
clipboard.PutInClipboard
End Sub
EDIT (additional background):
For accessing the information put on the Clipboard I created a custom QAT. One of the buttons on the toolbar opens the clipboard so they can easily begin to paste the name they need at any one time. Most reports involve two people so I want to send the value of two textboxes into the clipboard as if you individually selected and copied each name. My first idea was to assign a keyboard shortcut to the value of the two textboxes but I settled on utilizing the clipboard tab.
Given what you've told us, I'm guessing you're calling up the Office Clipboard. This is different from the Windows Clipboard, which is what your code is using. The Office Clipboard is not exposed to the developer (for internal, MS use only). There is a way to put information on it, but I'm uncertain how reliable it is; YMMV (your mileage may vary).
The code for your UserForm to call a procedure responsible for writing the information:
PutContentOnOfficeClipboard Me.[textBoxName].Value
PutContentOnOfficeClipboard Me.[textBoxName].Value
The procedure writes the text to the end of the document, copies it, then deletes again. In my tests, this all shows up on the Office Clipboard:
Sub PutContentOnOfficeClipboard(s As String)
Dim rng As word.Range
Set rng = ActiveDocument.Content
rng.Collapse wdCollapseEnd
rng.Text = s
rng.Copy
rng.Delete
End Sub
If it turns out to be unreliable, then you need a different approach. Here are some thoughts on alternative methods...
A taskpane is optimal as it makes the information visibly available users. Unfortunately, task panes aren't available to the VBA Developer. They can be used from a VSTO solution or an Office-JS solution, but that may be more effort than you're willing/able to put into the project (steep learning curve, enterprise deployment requirement, etc.)
Besides keyboard shortcuts (which aren't a bad idea to have in addition to any visible interface):
A dropdown list on the QAT or the Ribbon
Two buttons on the QAT or the Ribbon
Modify the Right-click (context) menu with two controls to which you can write the names as needed. (Requires call-back macros to make the dynamic update)
Save the entries as AutoText/Building Blocks, possibly to use in conjunction
with a BuildingBlock content control (which can be filtered to show only your entries; AutoText can also be used selectively from the keyboard).
Make a small, non-modal UserForm with buttons. You could optionally use the Windows API to make it "always on-top".

Autoshapes and charts flick like they're having a seizure when VBA code is run on Excel Dashboard

I have built a dashboard in excel for my work over the last 4 months. The workbook is well organized, by my estimation, with database sheets, "under the hood" calculation sheets and the top, user visible data exhibition sheets. Also, I have 5 VBA modules that perform several different tasks, mostly relating to control of what the users see on screen. In some cases, there are complex chains of macros that put the right numbers, autoforms and charts in the right places.
The thing is: whenever one of these chains goes off, my autoforms and charts quickly flick in and out of screen, even though i have the screen updating off when executing them. It is a very quick flicking that happens, but it happens all over my workbook, with all of my content. It's ok with the changing content, but it happens over some lined forms that I use accross all of my sheets, with hyperlinks for navigation.
Example:
Note that this happens in very quick succession, sometimes repeating several times before the code is finished running, kind of like a seizure. The problem does not affect the functionality, but is visually disturbing, and my boss would rather not having it. I have searched the internets and have not found anything useful, so any help is appreciated.
I'm using Office 2010 on windows XP.
I am now using an adaptive code snippet to toggle or untoggle ScreenUpdating and Calculation, it goes like this:
Public Sub LudicrousMode(ByVal Toggle As Boolean)
Dim LockStatus As Boolean
LockStatus = Sheets("Aux").Range("B1").Value
If Toggle = LockStatus Then GoTo SKIP
Application.ScreenUpdating = Not Toggle
Application.EnableEvents = Not Toggle
Application.DisplayAlerts = Not Toggle
Application.Calculation = IIf(Toggle, xlCalculationManual, xlCalculationAutomatic)
Sheets("Aux").Range("B1").Value = Toggle`
SKIP:
End Sub
It was able to stop the "seizures" for most of the subs, except for those with the hiding and unhiding of rows and columns. Any idea with that?

Excel: Fixed Button Position

Needing some help attaching an Excel/VBA button on an Excel sheet. I need it to stay in the same position on the screen regardless of how I scroll or zoom. Preferably, I need this on the bottom left or right of the screen.
I have tried adding a button. Then, I right clicked on the button. Clicked on Format Controls -> Properties -> selected Don't Move or Size With Cells. Am I missing something that's making this not work?
Thanks!
I know this post is old, but here's to anyone it could be useful. The VisibleRange property of ActiveWindow can solve this problem. Use something like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet.OLEObjects("MY_BUTTON'S_NAME")
.Top = ActiveWindow.VisibleRange.Top + ActiveWindow.VisibleRange.Height - 5
.Left = ActiveWindow.VisibleRange.Left + ActiveWindow.VisibleRange.Width - .Width - 5
End With
End Sub
Here is the idea that I put across the comment earlier today :) Typically we can get a Floating User Form by setting the Modal property of the form to be 0 which is indeed a Modeless state.
Basic Points to consider:
Look & Feel of the form to make it look like a Button (Not show title bar/Not Resizable/
Hidden Close Button etc)
Setting the position of the Button
Which Event should trigger the form-button (WorkBook Open)
What would you do with Form Initialize Event
Whcih Events should keep it stick to the same position alive
Further Points to consider:
You might only want to keep this button vissible for the workbook you are working, and if you open another instance of a workbook, do you still want to keep the button
If you minimize the Excel Window instance, how do you plan to manage the state of the button and keep it visible
Post about keep displaying a form even the workbook is minimized.
One other great reference I happend to see, (little bit technical) but worth the shot - at least to get to know the certain properties/methods that you could make use: Extending VBA User Form Control.
The article include the following info, and please note the last line as well :)
They give you access to capabilities that are not available from VBA or from the objects (UserForms, Workbooks, etc.,) that make up a VBA Project. When you call an API, you are bypassing VBA and calling directly upon Windows. This means that you do not get the safety mechanisms such as type checking that VBA normally provides. If you pass an invalid value to an API or (a very common mistake) use a ByRef parameter instead of a ByVal parameter, you will most likely completely and immediately crash Excel and you will lose all your unsaved work. I recommend that until you are confident that your API calls are solid you save your work before calling an API function.
Add new Row on the beginning of your WorkSheet and set your button on it, then:
Freeze Top Row
Right click → properties → placement → change to 3.

Excel Button Growing

I'm working on a workbook in Excel 2010 that someone else created (I don't know which version they were using) with a button in it that invokes a macro. There are a lot of macros defined, so I'm right-clicking on it to find out which one it calls, but the context menu doesn't appear. Instead, when I click off, the button gets larger. I can make this happen as many times in a row as I'd like. There is another button the same worksheet that has the same context menu problem, but instead of growing, the text shrinks each time. There is another button that functions normally when I do this.
Growing buttons in Excel is a fairly common issue, with several theories about why this happens, including the use of multiple monitors or using proportional fonts. I have yet to see a definitive answer about this, but there are several workarounds that may work for you.
Delete and re-create the buttons.
Programmatically set the height and width of the buttons when the workbook is opened and when a button is clicked.
Select the button with another object or two on the sheet and group them.
Don't use them at all.
My personal choice is #4. As an alternative to buttons, I either use hyperlinks or shapes with macros assigned to them.
I think you want to enter "Design Mode" in the work book:
You should be able to right-click on the button to see what it does after that.
I have this same issue. I have two Excel workbooks with similar buttons on each. This only happens on one of them, but it happens every time I open that file.
I have found a sort of work-around. I open a blank Excel document, then I open the affected one and the buttons do not change size any more. When I open the second one, I have to drag it into the window with the already-open file. If I double-click on it, it opens in a new window and the problem remains.
I have the same issue sometimes. In my case, I could replicate it 100% on one file but it was inconsistent on an virtually identical file. I also found the size error wasn't permanent -- I could save and reopen the file to restore the button's appearance. I could also create a new window and then discard the damaged window.
For me, the button resized when I accessed the sheet's HPageBreaks collection. I was able to avoid the problem by temporarily changing the window view as follows:
ActiveWindow.View = xlPageBreakPreview
' do pagination stuff using HPageBreaks
ActiveWindow.View = xlNormalView

maintaining image object visibility with vba

i am developing a large non-linear powerpoint which has many sub sections to it. This has necessitated a table of contents slide (TOC). in this slide i am representing each section with its own picture. also on the slide are 2 buttons which let the user switch between images. The buttons do this by setting the appropriate section image to visible and all the others to invisible, so that only one sections image is visible at a time. my goal is to make sure that whenever the user goes back to the table of contents slide that the slide displays the same section image each time, regardless of which section what entered the previous time, i.e. the image for section 1 should be visible whenever the user goes back to the table of contents. how do i go about doing this?
also, if i can find new sources to learn more about syntax and other vba coding, i would be most appreciative.
i already consult:
pptalchemy.co.uk
skp.mvps.org
msdn.microsoft.com
i just cannot find more good sites that will help.
I don't quite understand the situation, but one possibility:
Add another slide before the TOC. You could make it a duplicate of the TOC slide (with the image you want in place).
Instead of linking back to the "real" TOC slide, link to this one instead.
On this slide, add a rectangle that covers the entire slide, make it 99% transparent and give it a Run Macro mouse over action setting.
Have the macro do nothing more than set the image you want on slide 2 to be visible, then jump to slide 2 (the real TOC slide), eg
SlideShowWindows(1).View.GoToSlide(2)
The mouse over macro will trigger as soon as the user moves the mouse, and since that will trigger a jump from one slide to an identical one, it will be invisible to the user.
most of the solution came from [pptalchemy] (http://www.pptalchemy.co.uk/PowerPoint_Auto_Open_Code.html):
I downloaded the custom ui editor for microsoft office
I added the code from ppt alchemy to the custom ui editor for the slide show.
In vba i added the code:
Sub onloadcode()
Debug.Print "Running"
End Sub
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
If SSW.View.CurrentShowPosition = SSW.Presentation.Slides("TOC").SlideIndex Then
'code here'
end if
end sub
the code executes perfectly now, and i have condensed my table of contents from 9 slides down to 1. Just, don't add features to the code until you have everything in place to accept them. In my case i added the code for text boxes which did not exist yet and that messed up my code a lot. Once i made all of the objects for the code and then added the code it worked perfectly.