LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default vb6 form with listbox

Trying to show a VB6 form in Excel with a populated listbox, but not much
success sofar.
I started with an example from the book Professional Excel Development and
now have the following code:

In VB6:
---------------

A normal form with a listbox and a commandbutton with the code:

Private Sub cmdList_Click()
PopulateList
End Sub


A class module with the code:

Option Explicit
Private Const GWL_HWNDPARENT As Long = -8
Private mxlApp As Excel.Application
Private mlXLhWnd As Long
Private Declare Function FindWindowA _
Lib "user32" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As
Long
Private Declare Function SetWindowLongA _
Lib "user32" (ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Public Property Set ExcelApp(ByRef xlApp As Excel.Application)
Set mxlApp = xlApp
mlXLhWnd = FindWindowA(vbNullString, mxlApp.Caption)
End Property

Private Sub Class_Terminate()
Set mxlApp = Nothing
End Sub

Public Sub ShowVB6Form()
Dim frmHelloWorld As FHelloWorld
Set frmHelloWorld = New FHelloWorld
Load frmHelloWorld
SetWindowLongA frmHelloWorld.hwnd, GWL_HWNDPARENT, mlXLhWnd
frmHelloWorld.Show 0
Set frmHelloWorld = Nothing
End Sub


A module with the code:

Sub PopulateList()
Dim i As Long
For i = 1 To 3
FHelloWorld.List1.AddItem "item " & i
MsgBox "item " & i 'this shows fine
Next
FHelloWorld.List1.Refresh
End Sub

This will compiled to an ActiveX dll, AFirstProject.dll


In Excel:
------------------------

The .dll is referenced

A normal module with the code:

Public Sub DisplayDLLForm()

Dim clsHelloWorld As AFirstProject.CHelloWorld
Set clsHelloWorld = New AFirstProject.CHelloWorld
Set clsHelloWorld.ExcelApp = Application
clsHelloWorld.ShowVB6Form
Set clsHelloWorld = Nothing

End Sub

This Sub will load the form.
Clicking the button will show all the VB6 messages, but the listbox doesn't
get populated.
There is no error, but no items will show.
I must be overlooking something simple and fundamental here, but I can't see
it.
The idea of this is to get a form in Excel with a listbox that will scroll
with the mouse wheel.
Thanks for any advice.


RBS


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to filter listbox data in a form? Vinod Excel Discussion (Misc queries) 1 January 11th 10 02:01 PM
listbox works in form; not imbedded??? jasonsweeney[_66_] Excel Programming 3 April 15th 04 10:24 PM
listbox option in form inquirer Excel Programming 2 April 7th 04 02:16 AM
User form with a listbox John Green[_2_] Excel Programming 4 December 30th 03 07:18 PM
Listbox/Form question Stuart[_5_] Excel Programming 1 August 24th 03 04:53 PM


All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"