Consulting

Results 1 to 15 of 15

Thread: Locking Drawing objects on screen

  1. #1
    VBAX Contributor
    Joined
    Oct 2004
    Location
    Cardiff
    Posts
    120
    Location

    Locking Drawing objects on screen

    Hi all,

    I'm aware of how to change a drawing object's setting so that the object doesn't resize with cells etc. but is there any code that will lock an object's horizontal position even when the sheet is scrolled to the left or right?

    Regards

    Damo
    Last edited by The Tamer; 02-11-2005 at 05:16 AM. Reason: Change of Title
    You cannot solve all the world's major problems using only potatoes. :- Adams

    http://www.vbaexpress.com

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Is it not the case that
    <object>.Placement = xlFreeFloating
    means the object doesn't move or size with cells?
    K :-)

  3. #3
    VBAX Contributor
    Joined
    Oct 2004
    Location
    Cardiff
    Posts
    120
    Location
    Hi Killian

    I just tried that, but the object still disappears from view when you scroll the sheet...

    You cannot solve all the world's major problems using only potatoes. :- Adams

    http://www.vbaexpress.com

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Oh, now I understand... you want the object float over the sheet and stay fixed relative to the view...

    I've no idea how that could work. There's no event fired when the user scrolls (as far as I know) which makes it tricky.

    Depending on what you're doing you could split the window so the part with the object doesn't scroll. Other than that, the only thing I can think of that would sit above the worksheet while it's scrolled around in a modeless form
    K :-)

  5. #5
    VBAX Contributor
    Joined
    Oct 2004
    Location
    Cardiff
    Posts
    120
    Location
    Thanks anyway Killian.



    I guess Excel can't do everything!
    You cannot solve all the world's major problems using only potatoes. :- Adams

    http://www.vbaexpress.com

  6. #6
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Quote Originally Posted by The Tamer
    I guess Excel can't do everything!
    blasphemy!! That's 1000 lashes for you.

    Create a User Form and add this code.

    Option Explicit 
     
    Private Sub UserForm_Initialize()
    Call RemoveCaption(Me)
    End Sub
    Insert a module and add this code.

    Option Explicit
    
    Private Declare Function FindWindow Lib "User32" _
    Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowLong Lib "User32" _
    Alias "GetWindowLongA" ( _
    ByVal hwnd As Long, _
    ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "User32" _
    Alias "SetWindowLongA" (ByVal hwnd As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long
    Private Declare Function DrawMenuBar Lib "User32" ( _
    ByVal hwnd As Long) As Long
    
    Sub RemoveCaption(objForm As Object)
    Dim lStyle          As Long
    Dim hMenu           As Long
    Dim mhWndForm       As Long
    If Val(Application.Version) < 9 Then
            mhWndForm = FindWindow("ThunderXFrame", objForm.Caption)    'XL97
        Else
            mhWndForm = FindWindow("ThunderDFrame", objForm.Caption)    'XL2000+
        End If
        lStyle = GetWindowLong(mhWndForm, -16)
        lStyle = lStyle And Not &HC00000
        SetWindowLong mhWndForm, -16, lStyle
        DrawMenuBar mhWndForm
    End Sub
    
    Sub ShowForm()
    UserForm1.Show False
    End Sub
    Add whatever images you want to the User Form.

    See the attachment for an example.

  7. #7
    VBAX Contributor
    Joined
    Oct 2004
    Location
    Cardiff
    Posts
    120
    Location
    Hey Jake - thanks for helping me with this.

    It's probably an XL97 thing, but I'm getting a "Compile error: Wrong number of arguments or invalid property assignment" on the line "UserForm1.Show False", the .show is highlighted.

    Any Ideas mate?
    You cannot solve all the world's major problems using only potatoes. :- Adams

    http://www.vbaexpress.com

  8. #8
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Oh... Excel 97 you say...

    Well Excel 97 doesn't really support Modeless User Forms.

  9. #9
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Note that you can "trick" Excel 97 into making a User Form go Modeless. But this is only a glitch and I cannot guarantee that it won't crash Excel intermittently.

    Option Explicit
     
    Private Declare Function FindWindowA Lib "user32" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    Private Declare Function EnableWindow Lib "user32" ( _
    ByVal hWnd As Long, _
    ByVal bEnable As Long) As Long
     
    Private Sub UserForm_Activate()
    Dim mlHWnd As Long
    mlHWnd = FindWindowA("XLMAIN", Application.Caption)
    EnableWindow mlHWnd, 1
    Application.CellDragAndDrop = False
    End Sub

  10. #10
    VBAX Contributor
    Joined
    Oct 2004
    Location
    Cardiff
    Posts
    120
    Location
    Where do I paste this code Jake?

    (Sorry, I'm thick, remember?)
    You cannot solve all the world's major problems using only potatoes. :- Adams

    http://www.vbaexpress.com

  11. #11
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    It goes in the User Form code section. Just double click on the User Form and put in the the Code Window that opens up.

    Try the attachment and see if it goes Modeless.

  12. #12
    VBAX Contributor
    Joined
    Oct 2004
    Location
    Cardiff
    Posts
    120
    Location
    Nope, your attachment is still failing at ".show".
    You cannot solve all the world's major problems using only potatoes. :- Adams

    http://www.vbaexpress.com

  13. #13
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I forgot to take out the Modal argument.

    Change this:
    UserForm1.Show False
    To this:
    UserForm1.Show

  14. #14
    VBAX Contributor
    Joined
    Oct 2004
    Location
    Cardiff
    Posts
    120
    Location
    Hey, that works!

    Blast!! I AM a blasphemer!! Damn and double-damn!!!

    Cheers mate
    You cannot solve all the world's major problems using only potatoes. :- Adams

    http://www.vbaexpress.com

  15. #15
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Glad to help.

    Take Care

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •