VBA vs. Screen Size?

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
124
I have several macros that run just fine on my desktop monitor but don't run at all on my laptop screen. There is no error message, they just don't run.

They have the same resolution (1920x1080) but the laptop is 15.6" and the desktop is 22".

What causes this and is there any way around it?

Thanks in advance for your time,
~ Phil
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,140
Office Version
365
Platform
Windows
What exactly do these Macros do?
Does a simple macro like:
Code:
Sub Test()
    MsgBox "Hi"
End Sub
work?

Are these running from the same computer, or different computers?
If different computers, I suspect the security settings set so that you have macros/VBA disabled on the one.
 

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
124
Joe4,

It's the same computer. I have my laptop hooked up to a docking station and the laptop display & destop monitor are in extended screen mode.

The little snippet that says "Hi" just fine on either screen. Here are the two macros in question.

Code:
Private Sub CommandButton1_Click()

Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Application.ScreenUpdating = False

Set sht = Worksheets("Tracking")
Set StartCell = Range("A4")

'Refresh UsedRange
    Worksheets("Tracking").UsedRange

'Find Last Row and Column
    LastRow = StartCell.SpecialCells(xlCellTypeLastCell).Row
    LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column

'Select Range
    sht.Range(StartCell, sht.Cells(LastRow, LastColumn)).Select
    
'Name the selected range
    Selection.Name = ("ecolist")
  
'Sort the range
  Range("ecolist").Sort Key1:=Range("B4"), Order1:=xlAscending, Key2:=Range("A4"), Order2:=xlAscending, Header:=xlNo
    
Application.ScreenUpdating = True

End Sub

Private Sub CommandButton2_Click()
MSG1 = MsgBox("This action cannot be undone!" & vbCrLf & vbCrLf & "Selected Row is: " & ActiveCell.Row, 1, "CAUTION!")

Application.ScreenUpdating = False

If MSG1 = vbOK Then

    'Select row
        ActiveCell.EntireRow.Select

    'Return to Blank Format
        Selection.Interior.Color = xlNone
        Selection.Font.Strikethrough = False
        Selection.ClearContents
End If

Application.ScreenUpdating = True

End Sub
Thanks again for your time & assistance.

~ Phil
 
Last edited:

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,140
Office Version
365
Platform
Windows
What if you try putting breakpoints near the top of the macros, and then click the buttons, and go into the VB Editor, and see if it is stopped at that point (and what happens if you continually hit F8 - watch to see if it goes through or bombs out somewhere)?
 

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
124
It steps through with no problems, with & without stops. It does this with the VBAE on either screen, as well as when I'm undocked.

I'm going to delete the command buttons from the sheet, recreate them, and reassign them. I don't see any reason why this would help, but who knows . . .
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,140
Office Version
365
Platform
Windows
Not a bad idea to try that.

It does not make much sense to me that it would work when you step through it, but doesn't when you don't.
 

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
124
Finally had time to play with this. Buttons didn't make any difference.

I have these macros in the worksheet, not in This Workbook or a module. I'm going to make modules and try that.
 

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
718
Office Version
2007
Platform
Windows
Just a wild stab in the dark but maybe the screenupdating toggling you are doing works on the 'native' screen, but not on the docking screen? Maybe try taking out the screenupdating=false to see if they stay in sync. If that's it, then perhaps a recalc at the end might refresh things?
 

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
124
Re-did my macros as modules and they still wouldn't run when triggered from the ActiveX control button.

Deleted the ActiveX controls and replaced them with buttons from Form Controls pointing to the modules. Works fine now.

I still do not understand why it behaves this way.

Anybody know how to change the background color of a Form Control button?
 

Forum statistics

Threads
1,078,135
Messages
5,338,434
Members
399,234
Latest member
WaddoAU

Some videos you may like

This Week's Hot Topics

Top