With Application; Me.Top = ...

D

David

With Application
Me.Top = 0
Me.Left = 625
End With

Just hoping to advance my knowledge..
An old post of Norman Jones gave the above solution to initial positioning
of a userform on the screen using a With structure - works great.
I use 'With Structures' but this code is in a form that I've not come across
yet so it caught my eye.
I tried to educate myself by typing out the instruction without the With
Structure, eg: Application.me.top etc but I'm obviously missing a trick. Can
anyone advise what the code looks like without the 'With'?
Thanks in advance
 
J

John Bundy

the me is not necessary, you can just use
with application
..top=0
..left=625
end with

I use the me's as well. So just typing it without the with:
application.top=0
application.left=625

the with just lets you set multiple properties without retyping application.
 
B

Bob Phillips

Me.Top = 0
Me.Left = 625

The With Application seems superfluous to me in this code snippet.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

David

Thanks John,
The code is in a userform 'Activate' procedure
The 'me' must be referring to the userform
The 'with structure' in the original post sets the initial position of the
userform and not the excel application. (Your code sets the position of the
excel application on the screen)
Could you advise further on how the code is working? ie: How to write the
instructions without the 'With'
Thanks again
 
J

John Bundy

Ah, must have missed that part. In that case just use me.top, no application
is neccesary.
 
D

David

Thanks Bob,
It is superfluous, but what intrigues me is what would each line of code
look like with the 'Application' and 'Me.Top = 0' joined up into the same
line of code. Perhaps i'm looking for something that is not there and 'With
Application' 'End With' could be written around any set of instructions
without making any difference at all?
 
J

John Bundy

You might be having an issue because of how he structures it, application
contains the me, he has it but does not need it. I know that made no sense so
have a look at another way to do what he did:

With Me
..Top = 0
..Left = 150
End With

this works the same way and is easier to write and (i think) comprehend how
it would break down into
me.top=0
me.left=150
 
D

Dave Peterson

Only those properties/methods that start with a dot refer to the object in the
previous With statement.

Your code would have to look more like:

With Application
.Me.Top = 0
.Me.Left = 625
End With

And in this case, it's not right.
 
B

Bob Phillips

It doesn't get joined up because the Application is not qualifying Me, there
is no dot before Me.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

David

Thanks Bob, John & Dave for clearing that one up.
I'm sure I speak for 100s of people in saying that you do an excellent job
of improving our understanding of VBA
Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top