My ComboBox won't run in Excel VBA after switching computers - excel

I have been running my VBA code on a different computer without flaw, then I get a new computer and when I try to run my code, it says the following "Compile error in hidden module: Sheet4". Then when I press "OK" it takes me to my code and highlights the first ".ComboBox1" part of the following code.
Private Sub ComboBox_Change()
End Sub
Sub SpinButton1_SpinUp()
If Me.ComboBox1.ListIndex = Me.ComboBox1.ListCount - 1 Then Exit Sub
Me.ComboBox1.ListIndex = Me.ComboBox1.ListIndex+1
End Sub
FYI I am running a macro that calls SpinButton1_SpinUp. I haven't changed anything else about the code from the old computer to the new computer so now I don't know how to get rid of the error and be able to run my code properly.
Thank you in advance.

Related

Excel - VBA code linked to Hyperlink not running

I am trying to get some VBA code running when I click a hyperlink in excel. I am using the following test code but it is not working. I have tried placing the code (VBA editor) in the sheet, thisworkbook, and it's own module. Nothing works. What am I doing wrong? Is there some master setting that must be configure to run VBA code? I'm sure it's simple. :)
Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox "It Ran"
End Sub

1004: Application-Defined or Object defined error after switching from Excel 2013/2016 to 2010

it's a very simple macro and I read tons of threads, none of which resolves my case. I get the .Caption line highlighted. I tried to Dim the form as new form and it does not help as well.I have a form which I want to call from a button which is apparently not done correctly from my side.
Sub BtnAdd_Click()
frmAddCB.Caption = "Add Transaction"
frmAddCB.Show
End Sub
Cheers,
When executing this step by step with F8, just before the line that was highlighted on my standard module when executing with F5, it jumps to the Private Sub UserForm_Initialize() sub which is in the Form code itself. In that Initialize sub I had this line of code which was causing the error in Excel 2010:
TransTypeComboBox.List = Application.WorksheetFunction.Transpose(ThisWorkbook.Names("TransType").RefersToRange))
After I changed this to the old-school way with a loop, it started working properly. Probably something about my dynamic range or something about the RefersToRange is not working the same way after Excel 2010.
For Each TT In Range("TransType")
With Me.TransTypeComboBox
.AddItem TT.Value
End With
Next TT

Sheet select from a Userform button causes data entered to go on previous sheet

I call a macro called SelectSheet1, from a button on a userform, to select Sheet1.
When data is entered afterwards it is put on the previous sheet.
This is happening on Excel 2013. I confirmed it is not a problem in Excel 2007.
Also it is not a problem if the macro is run directly from the developer tab, keyboard shortcut, quick access toolbar or ribbon customization.
The userform command button code:
Private Sub CommandButton1_Click()
Call SelectSheet1
Unload UserForm1
End Sub
The SelectSheet1 macro selects the sheet:
Sub SelectSheet1()
Sheets("Sheet1").Activate
End Sub
Link to xlsm file in dropbox
Link to youtube video if you want to see with your own eyes
It is a strange error and wondering if it a problem with Excel 2013, something changed in the way they do things and possibly there is a workaround.
Make sure there is only a single sheet Select'ed before you Activate a sheet:
Sub SelectSheet1()
Sheets("Sheet1").Select
Sheets("Sheet1").Activate
End Sub
Remember: "Although only a single sheet may be Active, many may be Selected."
I was able to figure out how to get it to work, but not sure why this solves the issue.
Im unloading the Userform before call macro and I tried using select instead of Activate, those did not help. But after I switched so that the UserForm loads with vbModeless then my problem went away, not sure why this fixed it.
For me the key to fixing this issue was vbModeless, but would love if somebody who understood more could explain why.
Private Sub CommandButton1_Click()
Unload UserForm1
Call SelectSheet1
End Sub
Sub ShowMainMenu()
UserForm1.Show vbModeless
End Sub
Sub SelectSheet1()
Sheets("Sheet1").Select
End Sub

Workbook_Open() won't execute Excel 2011

Using Excel 2011 (should be same as Excel 2010)
Code is under the "ThisWorkbook" module in Excel
Events are enabled
Macros are enabled
I can't seem to get either Workbook_Open() or Workbook_BeforeClose() to execute. I've read numerous posts on the subject but no solution. Here is some simple test code that should execute but doesn't. Any help would be greatly appreciated.
Private Sub Workbook_Open()
ActiveSheet.Range("BL4").Value = "Open is working"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next 'in case the menu item has already been deleted
ActiveSheet.Range("BL5").Value = "Close is working"
End Sub
First make sure you have put this in this in the right place and have macros enabled.
Then, try adding this line to the workbook_open method:
MsgBox "HELLO"
Do you see the msg box? You're choice of cell looks a bit strange
Also, I think you need to use a .xlsm file not .xlsx (Although not sure on that one)
FInally, if a plugin calls something like this line, it could cause your events not to fire..
Application.EnableEvents = False
So make sure you have tested it with no other sheets or addins open.

Runtime Error: "Out of Memory" From Excel Macro

I have one macro, which is called when a cell change occurs. This macro selects images, deletes them, and inserts another image depending on a cell value using the following code. I have the same code for two sheets.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Shapes.SelectAll
Selection.Delete
'insert image code here.
End Sub
In one sheet, it's working perfectly fine and deletes all images, while in the other sheet, it gives me the runtime error "Out of Memory" and highlights the following line:
ActiveSheet.Shapes.SelectAll
Can anyone tell me why this is happening? It works perfectly fine in one and not in the other.
One other thing I want to tell you is it was working fine when I gave this Excel macro to my client; both sheets were working fine. Suddenly after 2 days, he started getting the error on one sheet on which he was working a lot.
I don't know why this is happening. Can anyone tell me what's the reason for this and how I can solve it?
Can you provide your insert image code?
If you are changing the current selection yourself in that code, then this procedure would be called endlessly. You should consider disabling events while processing this event handler as per the following code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
' do something
Application.EnableEvents = True
End Sub

Resources