+ Reply to Thread
Results 1 to 2 of 2

OLEObjects.Add strange behaviour

  1. #1
    Pierre Castelain
    Guest

    OLEObjects.Add strange behaviour

    I dont know if this the right place to submit what I suspect to be a bug
    in the OLEObjects Add method. Please apologize if not.

    When invoking the Add method on the OLEObjects collection of a worksheet
    we can indicate the coordinates and size of the control. This method
    seems not to work correctly when the zoom is set to a value lower than
    100%. The position of the control is good except for it's Top value.
    If the coordinates are set after the control's creation, the position is
    correct.
    Here is some example code :

    Sub IsThisABug()
    Dim aRange As range

    Application.ActiveWindow.Zoom = 50

    Set aRange = range("A1500")
    aRange.Select
    aRange.Show

    ' The control appears around cell A1416 instead of A1500
    Application.ActiveSheet.OLEObjects.Add "Forms.Combobox.1" _
    , , , , , , , _
    aRange.Left, aRange.Top, aRange.Width, aRange.Height

    Set aRange = Nothing
    End Sub

    Sub ThisOneWorks()
    Dim aRange As range

    Application.ActiveWindow.Zoom = 50

    Set aRange = range("A1500")
    aRange.Select
    aRange.Show

    ' The control appears exactly on cell A1500
    With Application.ActiveSheet.OLEObjects.Add("Forms.Combobox.1")
    .Left = aRange.Left
    .Top = aRange.Top
    .Width = aRange.Width
    .Height = aRange.Height
    End With

    Set aRange = Nothing
    End Sub

    I'm not an Excel or VBA expert, so I hope not to have missed something.

    PS: to contact me, replace the domain name of my address by prosim.net.

  2. #2
    Pierre Castelain
    Guest

    Re: OLEObjects.Add strange behaviour

    I forgot to mention that the "bug" can be reproduced on all versions of
    Excel I can test (97, 2000, XP, 2003).

    Pierre Castelain a écrit :
    > I dont know if this the right place to submit what I suspect to be a bug
    > in the OLEObjects Add method. Please apologize if not.
    >
    > When invoking the Add method on the OLEObjects collection of a worksheet
    > we can indicate the coordinates and size of the control. This method
    > seems not to work correctly when the zoom is set to a value lower than
    > 100%. The position of the control is good except for it's Top value.
    > If the coordinates are set after the control's creation, the position is
    > correct.
    > Here is some example code :
    >
    > Sub IsThisABug()
    > Dim aRange As range
    >
    > Application.ActiveWindow.Zoom = 50
    >
    > Set aRange = range("A1500")
    > aRange.Select
    > aRange.Show
    >
    > ' The control appears around cell A1416 instead of A1500
    > Application.ActiveSheet.OLEObjects.Add "Forms.Combobox.1" _
    > , , , , , , , _
    > aRange.Left, aRange.Top, aRange.Width, aRange.Height
    >
    > Set aRange = Nothing
    > End Sub
    >
    > Sub ThisOneWorks()
    > Dim aRange As range
    >
    > Application.ActiveWindow.Zoom = 50
    >
    > Set aRange = range("A1500")
    > aRange.Select
    > aRange.Show
    >
    > ' The control appears exactly on cell A1500
    > With Application.ActiveSheet.OLEObjects.Add("Forms.Combobox.1")
    > .Left = aRange.Left
    > .Top = aRange.Top
    > .Width = aRange.Width
    > .Height = aRange.Height
    > End With
    >
    > Set aRange = Nothing
    > End Sub
    >
    > I'm not an Excel or VBA expert, so I hope not to have missed something.
    >
    > PS: to contact me, replace the domain name of my address by prosim.net.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1