1

I've got an excel workbook witch uses activeX comboboxes to run VBA code. It works fine on most PCs.

However some of my clients find that when they click on the comboboxes the combobox appears to double up or duplicate, one on top of the other. Also the doubled up drop down doesn't function.

Here's an example (bottom combobox displays the issue):

Doubled up combo box

Here's the code - I'm afraid it calls 3 subroutines which are all quite lengthy:

Private Sub SegmentComboBox_Change()

Call DrawTabCCView
PopTab
Call CCViewAddFormulasNew

End Sub

DrawTabCCView

Sub DrawTabCCView()


Dim C As Range
Dim D As Range
Dim D2 As Range

Dim CountryCol As Integer
Dim SegDetCol As Integer
Dim CompetitionCol As Integer
Dim BrandCol As Integer
Dim CompCol As Integer
Dim TotX As Range, Comp As Range

Dim PrevLabel As String

Application.ScreenUpdating = False

ThisWorkbook.Sheets("Country_Category view").Activate

'clear old data
Set D = ActiveSheet.Range("C13")

If D.Value <> "Total Category" Then Stop

Do Until D.Value = "" And D.End(xlDown) = ""

    Select Case D.Value

    Case "Total Category", "Total", "Private Labels", "Competition"
        PrevLabel = D.Value
        D.EntireRow.ClearContents
        D.Value = PrevLabel

        If D.Value = "Total Category" Then
            Set TotCat = D
        ElseIf D.Value = "Total" Then
            Set TotX = D
        ElseIf D.Value = "Private Labels" Then
            Set PL = D
        ElseIf D.Value = "Competition" Then
            Set Comp = D
        End If




    Case ""

        'do nothing

    Case Else

        If D.Offset(-2, 0) <> "" Then
            D.EntireRow.ClearContents
        Else
            Set D = D.Offset(-1, 0)
            D(2, 1).EntireRow.Delete
        End If

    End Select



    Set D = D.Offset(1, 0)
Loop

Set C = ThisWorkbook.Sheets("Raw Data (2)").Cells(1, 1)

Do Until C.Value = ""

    If C.Value = "Country" Then CountryCol = C.Column
    If C.Value = "Segment + Detail" Then SegDetCol = C.Column
    If C.Value = "Competition" Then CompetitionCol = C.Column
    If C.Value = "Local_Brand_Name" Then BrandCol = C.Column
    If C.Value = "Competition" Then CompCol = C.Column

    Set C = C.Offset(0, 1)
Loop

If CountryCol = 0 Then Stop
If SegDetCol = 0 Then Stop
If CompetitionCol = 0 Then Stop

Set C = C.Parent.Cells(2, 1)
Do Until C.Value = ""
    If C(1, CountryCol).Value = ActiveSheet.CountryComboBox.Value And C(1, SegDetCol).Value = ActiveSheet.SegmentComboBox.Value Then

        Select Case C(1, BrandCol)

        Case "Total Category", "Private Labels", "Total", "Dummy"
            'do nothing
        Case Else

            If C(1, CompCol) = "XXX" Then
                Set D = TotX.Offset(2, 0)
            ElseIf C(1, CompCol) = "Competition" Then
                Set D = Comp.Offset(2, 0)
            Else
                Stop
            End If

            Do Until D.Value = ""
                Set D = D.Offset(1, 0)
            Loop

            If D.Offset(-1, 0).Value <> "" Then
                D.EntireRow.Insert
                Set D = D.Offset(-1, 0)
            End If

            D.Value = C(1, BrandCol).Value

        End Select


    End If
    Set C = C.Offset(1, 0)
Loop



Application.ScreenUpdating = True


End Sub

PopTab

Sub PopTab()

Call PopulateTables(ThisWorkbook.ActiveSheet)
ActiveSheet.Range("A1").Activate

End Sub

CCViewAddFormulasNew

Sub CCViewAddFormulasNew()

Dim D As Range
Dim D2 As Range
Dim TabFilter(1 To 2, 4) As Variant


TabFilter(1, 0) = "Measure"
TabFilter(1, 1) = "Country"
TabFilter(1, 2) = "Segment + Detail"
TabFilter(1, 3) = "Period"
TabFilter(1, 4) = "Local_Brand_Name"

TabFilter(2, 0) = "XXX"
TabFilter(2, 1) = ActiveSheet.CountryComboBox.Value
TabFilter(2, 2) = ActiveSheet.SegmentComboBox.Value
TabFilter(2, 3) = "XXX"
TabFilter(2, 4) = "XXX"


Application.ScreenUpdating = False
If DontUpdate = False Then
    'Stop

    Set D = ThisWorkbook.Sheets("Country_Category view").Range("C13")

    Do Until D.Value = "" And D.End(xlDown).Value = ""
        If D.Value <> "" Then
            Set D2 = D(1, 3)

            'brand
            TabFilter(2, 4) = D.Value


            Do Until D2.Parent.Cells(11, D2.Column) = "" And D2.Parent.Cells(11, D2.Column + 1) = ""

                    TabFilter(1, 0) = D2.Parent.Cells(10, D2.Column).Value

                    TabFilter(2, 3) = D2.Parent.Cells(11, D2.Column).Value
                    D2.Value = FindValPivot(ThisWorkbook.Sheets("Raw Data"), TabFilter())

                    TabFilter(2, 3) = D2.Parent.Cells(11, D2.Column + 1).Value
                    D2(1, 2).Value = FindValPivot(ThisWorkbook.Sheets("Raw Data"), TabFilter())

                    If D2.Value <> "" And D2(1, 2).Value <> "" Then
                        D2(1, 3).FormulaR1C1 = "=RC[-1]/RC[-2] * 100"
                    End If

                    If IsError(D2(1, 3).Value) Then D2(1, 3).Value = "n/a"

                Set D2 = D2.Offset(0, 4)
            Loop
        End If

        Set D = D.Offset(1, 0)
    Loop

End If

Application.ScreenUpdating = True

ActiveSheet.Range("A1").Activate

End Sub

Any idea how to stop this happening?

Cheers!

Oliver Humphreys
  • 418
  • 1
  • 5
  • 17
  • You can post screenshot by uploading it to other free site and post the link in your question. – R.Katnaan Aug 07 '15 at 10:58
  • Do they have dual monitors? That can sometimes cause an issue with activeX. – Excel Developers Aug 07 '15 at 10:59
  • Also, please post the code for comboboxes that causes the duplication – paul bica Aug 07 '15 at 12:00
  • I Just added the code within the combobox. I'm afraid it won't be a great deal of help though. – Oliver Humphreys Aug 07 '15 at 12:31
  • Unfortunately I can't find an image hosting site which isn't blocked by my companies firewall :-( – Oliver Humphreys Aug 07 '15 at 12:32
  • can you post the code fro DrawTabCCView, PopTab, and CCViewAddFormulasNew as well? (that's where the issue is caused) – paul bica Aug 07 '15 at 13:24
  • I just added a picture of the issue. – Oliver Humphreys Aug 10 '15 at 14:39
  • I've just added the subroutine code (sorry it took so long). I'm afraid it calls yet more subroutines! the full code is really huge so I can't put it all here. it occurs to me it may be due to adding rows with Application.Screenupdating turned off? @paulbica – Oliver Humphreys Aug 12 '15 at 16:39
  • there are a few potential issues in the code you posted, possibly in other subs as well. An unusual one is related to **Stop** - _Stop statement suspends execution, but unlike End, it doesn't close any files or clear variables_; the environment is left unstable after it (a restart of Excel would fix it). If your intent is not to continue the execution of code at that point you should use **Exit Sub** (or "Exit Function" whatever the procedure is). Another subtle issue is the use of "ActiveSheet" in relation to comboBoxes (`ActiveSheet.CountryComboBox`, `ActiveSheet.SegmentComboBox`) (cont) – paul bica Aug 12 '15 at 23:11
  • The ActiveSheet implies that there are multiple sheets, and all of them contain combo boxes named "CountryComboBox", and "SegmentComboBox". I would need to see the structure of the file, and all code to investigate further, but you need to search for any lines of code that involve the combo boxes with ambiguous references. In some circumstances Excel might create new objects with default names (like ComboBox1, 2, 3, etc) place them on the active sheet and they will not have any code associated with them (won't do anything) – paul bica Aug 12 '15 at 23:18
  • Thanks Paul. The Stop lines were there just for debugging when I developed the tool, so the end users will never have triggered them. However I'll have a go at making the combobox references more concise hopefully that will work. – Oliver Humphreys Aug 13 '15 at 09:18
  • I've discoverd that this issue occurs on machines running Excel 2013. Is anyone else aware of this? I'm going to investigate further... – Oliver Humphreys Oct 07 '15 at 17:18
  • Did the investigations get any further? I have same issue when circulating to some users running 2013. – QHarr Nov 21 '17 at 10:18
  • @QHarr I'm afraid we've not found a simple solution. however we have discovered similar issues occur when the screen resolution changes whilst the files containing the activex control are open. ie if the pc is plugged into a docing station or projector when the file is already open. This usually results in the control changing size rather than doubling up but it's worth investigating on your problem PCs. – Oliver Humphreys Nov 23 '17 at 09:36
  • @OliverHumphreys Thanks for responding. These users have Excel 2013 , 32 bit desktop tower units. I have a 64 bit laptop Excel 2016 no issue on mine. Issues on theirs :-( I have had to change all the Active X to Forms controls and am now left with the tiny text issue. The Forms control doubles to some extent but seems to be masked by the foreground image and selection is still allowed. Not ideal. Sigh. Did you find a different way to handle this that presented users with a workable solution? – QHarr Nov 23 '17 at 10:21
  • @OliverHumphreys Spot on with screen resolution point. Just tested some machines and seems is related to this as same screen resolutions are fine, independent of Excel version, but different screen resolutions...bang.....problems. – QHarr Nov 23 '17 at 10:36
  • Did just find this though https://stackoverflow.com/questions/19385803/how-to-stop-activex-objects-automatically-changing-size-in-office – QHarr Nov 23 '17 at 10:48

1 Answers1

1

For the sake of completeness here is the solution that worked for me. I adapted the code from enderland.

As noted in comments by @Oliver Humphreys, this seems to be related to differing screen resolutions. I tested on a number of different machines, with different versions of Excel, using the following cmd command to verify test machines screen dimensions.

wmic desktopmonitor get screenheight, screenwidth

The machines with the same dimensions showed no problem with the ActiveX double-image. Those with differing dimensions did, irrespective of Excel version or 32/64 bit.

I have adapted the source code to loop each sheet and write out the settings of each ActiveX object, to a text file, with a space in between each object's details.

I put this code in a standard module, on the development machine I use, and ran it from there. You could in theory run this on individual machines, where you create an ActiveX object of particular dimensions, and then use those dimensions.

I then used the output information to set up Workbook_Open event. In this event I set the properties for all the ActiveX controls. And voilà, no more double image and the object functions as expected. Users versions had only the Workbook_Open Code in.

The reason for leaving the Workbook_Open code in the distributed workbooks is in case of onward distribution.

Code to get existing dimensions:

Option Explicit

Private Sub printAllActiveXSizeInformation()

    Dim myWS As Worksheet
    Dim OLEobj As OLEObject
    Dim obName As String
    Dim shName As String
    Dim mFile As String
    mFile = "C:\Users\yourusername\Desktop\ActiveXInfo.txt"

    Open mFile For Output As #1


    For Each myWS In ThisWorkbook.Worksheets

        shName = myWS.Name

        With myWS

            For Each OLEobj In myWS.OLEObjects

                obName = OLEobj.Name

                Print #1, "'" + obName
                Print #1, shName + "." + obName + ".Left=" + CStr(OLEobj.Left)
                Print #1, shName + "." + obName + ".Width=" + CStr(OLEobj.Width)
                Print #1, shName + "." + obName + ".Height=" + CStr(OLEobj.Height)
                Print #1, shName + "." + obName + ".Top=" + CStr(OLEobj.Top)
                Print #1, "ActiveSheet.Shapes(""" + obName + """).ScaleHeight 1.25, msoFalse, msoScaleFromTopLeft"
                Print #1, "ActiveSheet.Shapes(""" + obName + """).ScaleHeight 0.8, msoFalse, msoScaleFromTopLeft"
                Print #1, vbNewLine

            Next OLEobj

        End With

    Next myWS

    Close #1

    Shell "NotePad " + mFile

End Sub

Example Workbook_Open event code:

Private Sub Workbook_Open()

    Dim wb As Workbook
    Dim ws as Worksheet
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets("Sheet1")  'add more as appropriate

    With ws

      .OLEObjects("ComboBox1").Left = 269
      .OLEObjects("ComboBox1").Width = 173
      .OLEObjects("ComboBox1").Height = 52.5
      .OLEObjects("ComboBox1").Top = 179.5
      .Shapes("ComboBox1").ScaleHeight 1.25, msoFalse, msoScaleFromTopLeft

    End With

End Sub

Alternatively, switch to form controls.

QHarr
  • 83,427
  • 12
  • 54
  • 101