Consulting

Results 1 to 5 of 5

Thread: ACTIVE X CONTROL MOVES POSITION WHEN MACRO IS RUN

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    ACTIVE X CONTROL MOVES POSITION WHEN MACRO IS RUN

    I am running a macro that unhides rows and inserts an active x check box in my worksheet.
    When the macro is run, the check box is placed on row 23, instead of where I want it to
    be, E7.


    My code is:

    With ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", _
        Left:=179, Top:=74, Width:=54.5, Height:=16)
            .Name = "Checkbox1"
            .Object.Caption = "Confirm"
        End With
        
        With ActiveSheet.OLEObjects("CheckBox1").Object
            .Font.Name = "Source Sans Pro"
            .Font.Size = 11
            .SpecialEffect = 0
            .BackStyle = 1
            .BackColor = RGB(47, 117, 181)
            .TextAlign = 2
        End With
    Rows("5:21").EntireRow.Hidden = False
    End Sub
    Any ideas?

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Seems to work OK here.

    I did change the macro a little, but the original still was (basically) near E7

    Capture.JPG

    Option Explicit
    Sub test()
        Dim r As Range
        
        Set r = ActiveSheet.Range("E7")
    
    
        With ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", _
            Left:=r.Left, Top:=r.Top, Width:=2 * r.Width, Height:=2 * r.Height)
            .Name = "Checkbox1"
            .Object.Caption = "Confirm"
        End With
        
        With ActiveSheet.OLEObjects("CheckBox1").Object
            .Font.Name = "Source Sans Pro"
            .Font.Size = 11
            .SpecialEffect = 0
            .BackStyle = fmBackStyleOpaque
            .BackColor = RGB(47, 117, 181)
            .TextAlign = fmTextAlignLeft
        End With
        Rows("5:21").EntireRow.Hidden = False
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location
    Hi Paul,

    Thank you for responding. Even with the changes you suggested, I still have the same problem.

  4. #4
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    As Paul indicated, running your macro places the checkbox pretty much on E7 here as well.

    Here is a different macro that will place the checkbox exactly on E7 ... if you want to use it :

    Option Explicit
    
    
    Sub AddBox()
        Dim AddRow As Long
        Dim MyLeft As Double
        Dim MyTop As Double
        Dim MyHeight As Double
        Dim MyWidth As Double
        AddRow = 7
        
                MyLeft = Cells(AddRow, "E").Left
                MyTop = Cells(AddRow, "E").Top
                MyHeight = Cells(AddRow, "E").Height
                MyWidth = MyHeight = Cells(AddRow, "E").Width
                
                ActiveSheet.CheckBoxes.Add(MyLeft, MyTop, MyWidth, MyHeight).Select
                With Selection
                    .Caption = ""
                    .Value = xlOff
                    '.LinkedCell = "A" & AddRow
                    .Display3DShading = False
    End With
    End Sub

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by DeanP View Post
    Hi Paul,

    Thank you for responding. Even with the changes you suggested, I still have the same problem.
    Can you post a sample workbook that shows the issue? There might be something else going on
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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