User-defined type not defined

adam2079

Board Regular
Joined
May 15, 2008
Messages
51
Morning all,

I have set up a user form with a dynamic listview. The code is as follows:

Code:
Option Explicit
Public WithEvents lvwDocList As MSComctlLib.ListView
Private Sub UserForm_Initialize()
    Set lvwDocList = Me.Controls.Add("MSComctlLib.ListViewCtrl.2", "ListView1")
    
    With lvwDocList
        .Appearance = ccFlat
        .BorderStyle = ccNone
        .Left = 0
        .Top = 0
        .Height = 100
        .Width = 100
        .HideColumnHeaders = True
        .View = lvwReport
        .Gridlines = True
        .FullRowSelect = True
        .CheckBoxes = False
        .HideSelection = False
        .LabelEdit = lvwManual
        .ColumnHeaders.Add , , "Column1", 25, lvwColumnLeft
        .ColumnHeaders.Add , , "Column2", 25, lvwColumnLeft
        .ColumnHeaders.Add , , "Column3", 25, lvwColumnLeft
        .ColumnHeaders.Add , , "Column4", 25, lvwColumnLeft
    End With
    
End Sub

When the user form loads it highlights the following:

Code:
Public WithEvents lvwDocList As MSComctlLib.ListView

with the error:

Compile Error: User-defined type not defined

If I drag a listview on to the form and then delete it the above code works fine.

What am I missing to allow me to create a dynamic listview without having to add the control first via the toolbox

Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I reckon the way you've gone about it is quicker. You need to add the relevant reference. In the VBE go: Tools -> References -> Browse for $WinSysPath\mscomctl.ocx
 
Upvote 0
Thanks for the quick response,

Is there any way of doing this via code? If not and I was to send this project out with the code protected to another user, how would they get past the compile error?
 
Upvote 0
The reference is added to the project so your users shouldn't get a compile error.
 
Upvote 0
That was what I was hoping for. The problem is that it does work on some users pc's and on others I get:

Compile Error: Can't find project or Library
 
Upvote 0
It would seem that the MSCOMCTL.OCX file was deregistered by one of the recent updates. At least that is a cause I found doing a google search.


Please try reregistering the two .OCX files:
Go to - C:\windows\system32\ and run "regsvr32 mscomctl.ocx" (for 32 bit Win7)
Go to - C:\windows\syswow64\ and run "regsvr32 mscomctl.ocx" (for 64 bit Win7)
 
Upvote 0
Do the users for whom it fails have different versions of Office or Windows to you? (if they have 64bit office you are out of luck)
 
Upvote 0
The MSCOMCTL.OCX issue has been giving me a headache for months - ever since August of last year.

Our technical team have been un-registering and re-registering MSCOMCTL.OCX v6.01.9833 on well over 100 users pc's / desktops. This has been working as a temporary solution to combat Compile error in hidden module.

Earlier this month I updated from Excel 2007 to Excel 2013 and now as soon as I save an excel spreadsheet containing controls using MSCOMCTL.OCX it immediately becomes corrupted to all other users. Our technical team do not have a solution.

A work around I thought of was to create the controls dynamically to remove the compatibility issue. This worked fine when I ran it on my colleagues machine (running Windows 7 64 bit Excel 2010) which filled me with hope, however, today when I ran it on another users machine (running Windows XP - Excel 2003) I got the error Compile Error: Can't find project or Library. I'm running Windows 7 64 bit Excel 2013.

My first thought was to revert back to Excel 2007 but that wouldn't resolve the issue and will just mean it will need fixing as other users upgrade to Excel 2013

Furthermore our technical team who have Windows 8 Excel 2013 have Microsoft Windows Common Controls 6.0 (SP6) checked in references but in the toolbox you cannot add any of the controls, for example Microsoft Listview Control, they simply don't exist, this means they cannot get any of my spreadsheets to work either. The technical leader told me that Microsoft are no longer supporting MSCOMCTL.OCX but I find no reference of this on any forum.

I'm literally at a standstill.
 
Upvote 0

Forum statistics

Threads
1,215,616
Messages
6,125,865
Members
449,266
Latest member
davinroach

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top