ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Form Creation (https://www.excelbanter.com/excel-programming/338535-form-creation.html)

William Barnes[_2_]

Form Creation
 
I'm unsure how to proceed with the following task:
What I'd like to do is to create a class that can if needed create and
display an Excel Userform. I've tried adding a reference to the Forms Object
Library and then creating an object reference of type Userform in my class,
e.g.

dim frmMyForm as Userform

The compiler accepts that but does not accept:

Set frmMyForm = New Userform

In addition, Intellisense does not offer a Show method for frmMyForm
generating an error if I write

Public Sub ShowMyForm()
frmMyForm.Show
End Sub

Can anyone point me to a source of enlightenment?

Thanks
William



Tom Ogilvy

Form Creation
 
Why not just create a custom userform (set name to frmMyForm as an example)
complete with event code and so forth, then you can do: (The code module
associated with a userform is already a class module).


Sub ABC()
Dim frm As frmMyForm
Dim frm1 As frmMyForm
Set frm = New frmMyForm
Set frm1 = New frmMyForm
frm.Caption = "ABCD"
frm1.Caption = "EFGH"
frm.Show
frm1.Show
End Sub


--
Regards,
Tom Ogilvy


"William Barnes" wrote in message
...
I'm unsure how to proceed with the following task:
What I'd like to do is to create a class that can if needed create and
display an Excel Userform. I've tried adding a reference to the Forms

Object
Library and then creating an object reference of type Userform in my

class,
e.g.

dim frmMyForm as Userform

The compiler accepts that but does not accept:

Set frmMyForm = New Userform

In addition, Intellisense does not offer a Show method for frmMyForm
generating an error if I write

Public Sub ShowMyForm()
frmMyForm.Show
End Sub

Can anyone point me to a source of enlightenment?

Thanks
William





William Barnes[_2_]

Form Creation
 
Well, I guess what I had in mind was to be able to create a class that could
be more or less self-contained, i.e., not dependent upon other files such as
the file associated with the independently created Userform. I guess there's
not really a good way to do this with VBA. Even if you write code using the
VBIDE reference, you still have to create a separate Userform object within
the VBAProject.
Thanks
William

"Tom Ogilvy" wrote in message
...
Why not just create a custom userform (set name to frmMyForm as an
example)
complete with event code and so forth, then you can do: (The code module
associated with a userform is already a class module).


Sub ABC()
Dim frm As frmMyForm
Dim frm1 As frmMyForm
Set frm = New frmMyForm
Set frm1 = New frmMyForm
frm.Caption = "ABCD"
frm1.Caption = "EFGH"
frm.Show
frm1.Show
End Sub


--
Regards,
Tom Ogilvy


"William Barnes" wrote in message
...
I'm unsure how to proceed with the following task:
What I'd like to do is to create a class that can if needed create and
display an Excel Userform. I've tried adding a reference to the Forms

Object
Library and then creating an object reference of type Userform in my

class,
e.g.

dim frmMyForm as Userform

The compiler accepts that but does not accept:

Set frmMyForm = New Userform

In addition, Intellisense does not offer a Show method for frmMyForm
generating an error if I write

Public Sub ShowMyForm()
frmMyForm.Show
End Sub

Can anyone point me to a source of enlightenment?

Thanks
William







Bob Phillips[_6_]

Form Creation
 
It sounds to me that you are referring to a VB executable that would then do
stuff with Excel via automation. You still have the same issue with the form
though and would be better to create the form in the VB project.

In Excel, you could create an add-in with a form class and do your stuff
from there, but it is a bit difficult trying to guess what your objective
really is.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"William Barnes" wrote in message
...
Well, I guess what I had in mind was to be able to create a class that

could
be more or less self-contained, i.e., not dependent upon other files such

as
the file associated with the independently created Userform. I guess

there's
not really a good way to do this with VBA. Even if you write code using

the
VBIDE reference, you still have to create a separate Userform object

within
the VBAProject.
Thanks
William

"Tom Ogilvy" wrote in message
...
Why not just create a custom userform (set name to frmMyForm as an
example)
complete with event code and so forth, then you can do: (The code

module
associated with a userform is already a class module).


Sub ABC()
Dim frm As frmMyForm
Dim frm1 As frmMyForm
Set frm = New frmMyForm
Set frm1 = New frmMyForm
frm.Caption = "ABCD"
frm1.Caption = "EFGH"
frm.Show
frm1.Show
End Sub


--
Regards,
Tom Ogilvy


"William Barnes" wrote in message
...
I'm unsure how to proceed with the following task:
What I'd like to do is to create a class that can if needed create and
display an Excel Userform. I've tried adding a reference to the Forms

Object
Library and then creating an object reference of type Userform in my

class,
e.g.

dim frmMyForm as Userform

The compiler accepts that but does not accept:

Set frmMyForm = New Userform

In addition, Intellisense does not offer a Show method for frmMyForm
generating an error if I write

Public Sub ShowMyForm()
frmMyForm.Show
End Sub

Can anyone point me to a source of enlightenment?

Thanks
William










All times are GMT +1. The time now is 07:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com