VBA ActiveWindow problem

cgmojoco

Well-known Member
Joined
Jan 15, 2005
Messages
699
I'm using this code to update a userform (this is code that is part of a progress bar):
Code:
Private Sub UserForm_Activate()
Dim lTop As Long, lLeft As Long
Dim lRow As Long, lCol As Long
    With ActiveWindow.VisibleRange
        lRow = .Rows.Count / 2
        lCol = .Columns.Count / 2
    End With
    With Cells(lRow, lCol)
        lTop = .Top
        lLeft = .Left
    End With
    With Me
        .Top = lTop
        .Left = lLeft
    End With
End Sub

Is there a way to do the same thing without having to focus on the activewindow (if I go to surf the net while this script is called in one of my subroutines I get an error---I'm assuming excel can't find the activewindow?)
 
the "activewindow" is considered as related to the proram itself
whatever other program is active, VBA editor included, does not matter

but you gave a new clue
you said, even when I go back to Excel the error occurs
when getting a "top" property of a cell :unsure:
I assume that you will have the same problem with the "left"
you can test that by disabling or hardcoding the "top"line
'lTop = .Top
lTop = 200

I really do not see where the problem could be...

Additional question:
What is showing the userform? Why does it appear when Excel is not active?
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Erik-

Sent an email to you just now

Please be discrete (although I deleted all data pertinent to the company there may be some proprietary formats)
And....do not laugh at my inefficient code...well that might be hard not to do...
:oops:

Update, hardcoding did the trick!

THANK YOU THANK YOU THANK YOU THANK YOU
 
Upvote 0
of course hardcoding does the trick :biggrin:
investigating your workbook didn't help

mystery 1.
how did the error occur ???
mystery 2.
why did you use that code?

1. Perhaps we will never know without sitting at your desk.
2. I'm still wondering why you choose to position the userform that way. Feel free to not anwer this. My curiosity doesn't reach that far. ;)
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top