Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Does Userform exist?

Hi All

I have a macro that makes use of a UserForm for gathering data from the
user. While the userform should always exist on the users' machines this
might not always be the case. Is anybody aware of a way of checking to see
if a UserForm exists in the Personal.xls workbook so I can handle such
instances? If it doesn't then there is obviously a compile error so I have
had a look at the #const and #if... directives but can't figure it out.

Thanks

Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Does Userform exist?

Look at Chip Pearson's page on programming the VBE

http://www.cpearson.com/excel/vbe.htm

--
Regards,
Tom Ogilvy


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering data from the
user. While the userform should always exist on the users' machines this
might not always be the case. Is anybody aware of a way of checking to

see
if a UserForm exists in the Personal.xls workbook so I can handle such
instances? If it doesn't then there is obviously a compile error so I

have
had a look at the #const and #if... directives but can't figure it out.

Thanks

Andy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Does Userform exist?

Hi Andy,

This demonstrates it

Dim oUserForm As Object
On Error Resume Next
Set oUserForm = UserForms.Add("Some form name")
On Error GoTo 0
If oUserForm Is Nothing Then
MsgBox "The Userform was not found.", vbExclamation, "Load userforn
by name"
End If


--

HTH

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


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering data from the
user. While the userform should always exist on the users' machines this
might not always be the case. Is anybody aware of a way of checking to

see
if a UserForm exists in the Personal.xls workbook so I can handle such
instances? If it doesn't then there is obviously a compile error so I

have
had a look at the #const and #if... directives but can't figure it out.

Thanks

Andy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Does Userform exist?

Just for clarification, this code would be used within a workbook containing
the userform. It would not work as code housed external to the workbook
containing the useform.

Your explanation of what you want is somewhat ambiguous - this is Bob's
interpretation and mine was a differnt interpretation of what you want.


--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...
Hi Andy,

This demonstrates it

Dim oUserForm As Object
On Error Resume Next
Set oUserForm = UserForms.Add("Some form name")
On Error GoTo 0
If oUserForm Is Nothing Then
MsgBox "The Userform was not found.", vbExclamation, "Load

userforn
by name"
End If


--

HTH

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


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering data from the
user. While the userform should always exist on the users' machines

this
might not always be the case. Is anybody aware of a way of checking to

see
if a UserForm exists in the Personal.xls workbook so I can handle such
instances? If it doesn't then there is obviously a compile error so I

have
had a look at the #const and #if... directives but can't figure it out.

Thanks

Andy





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Does Userform exist?

There is no way with conditional compilation to determine whether
a userform exists. Why are you assuming that the form should be
in the user's personal.xls workbook? This is bad program design.
Personal.xls is, by definition, where users put the own personal
code. Why don't you put the form in your workbook, so you can be
assured that it exists.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering data
from the
user. While the userform should always exist on the users'
machines this
might not always be the case. Is anybody aware of a way of
checking to see
if a UserForm exists in the Personal.xls workbook so I can
handle such
instances? If it doesn't then there is obviously a compile
error so I have
had a look at the #const and #if... directives but can't figure
it out.

Thanks

Andy





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Does Userform exist?

Thanks Tom/Bob

I think that Bob's code will be sufficient for my needs this time but the
link to Chip's website will be useful in the future and answers a few
questions that have rattled around at the back of my brain for a while!

Apologies for the ambiguous question - it can be difficult to phrase it
clearly when you don't know what all the options are.

Thanks very much

Andy

"Tom Ogilvy" wrote:

Just for clarification, this code would be used within a workbook containing
the userform. It would not work as code housed external to the workbook
containing the useform.

Your explanation of what you want is somewhat ambiguous - this is Bob's
interpretation and mine was a differnt interpretation of what you want.


--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...
Hi Andy,

This demonstrates it

Dim oUserForm As Object
On Error Resume Next
Set oUserForm = UserForms.Add("Some form name")
On Error GoTo 0
If oUserForm Is Nothing Then
MsgBox "The Userform was not found.", vbExclamation, "Load

userforn
by name"
End If


--

HTH

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


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering data from the
user. While the userform should always exist on the users' machines

this
might not always be the case. Is anybody aware of a way of checking to

see
if a UserForm exists in the Personal.xls workbook so I can handle such
instances? If it doesn't then there is obviously a compile error so I

have
had a look at the #const and #if... directives but can't figure it out.

Thanks

Andy






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Does Userform exist?

Hi Chip

Thanks for the reply, the macro needs to be run against different (new)
workbooks every time so there is not one workbook that the users will always
use. However, I take your point that importing modules into people's
personal.xls workbooks is bad program design. Would I therefore be better to
have a workbook with the sole purpose of containing common macros that opens
on startup?

Thanks
Andy

"Chip Pearson" wrote:

There is no way with conditional compilation to determine whether
a userform exists. Why are you assuming that the form should be
in the user's personal.xls workbook? This is bad program design.
Personal.xls is, by definition, where users put the own personal
code. Why don't you put the form in your workbook, so you can be
assured that it exists.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering data
from the
user. While the userform should always exist on the users'
machines this
might not always be the case. Is anybody aware of a way of
checking to see
if a UserForm exists in the Personal.xls workbook so I can
handle such
instances? If it doesn't then there is obviously a compile
error so I have
had a look at the #const and #if... directives but can't figure
it out.

Thanks

Andy




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Does Userform exist?

You could put your code and forms in an add-in and distribute
that to your users. I would never use anything that did anything
to my personal.xls file.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Andy" wrote in message
...
Hi Chip

Thanks for the reply, the macro needs to be run against
different (new)
workbooks every time so there is not one workbook that the
users will always
use. However, I take your point that importing modules into
people's
personal.xls workbooks is bad program design. Would I
therefore be better to
have a workbook with the sole purpose of containing common
macros that opens
on startup?

Thanks
Andy

"Chip Pearson" wrote:

There is no way with conditional compilation to determine
whether
a userform exists. Why are you assuming that the form should
be
in the user's personal.xls workbook? This is bad program
design.
Personal.xls is, by definition, where users put the own
personal
code. Why don't you put the form in your workbook, so you can
be
assured that it exists.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering
data
from the
user. While the userform should always exist on the users'
machines this
might not always be the case. Is anybody aware of a way of
checking to see
if a UserForm exists in the Personal.xls workbook so I can
handle such
instances? If it doesn't then there is obviously a compile
error so I have
had a look at the #const and #if... directives but can't
figure
it out.

Thanks

Andy






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Does Userform exist?

Thanks for your advice Chip.

Andy

"Chip Pearson" wrote:

You could put your code and forms in an add-in and distribute
that to your users. I would never use anything that did anything
to my personal.xls file.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Andy" wrote in message
...
Hi Chip

Thanks for the reply, the macro needs to be run against
different (new)
workbooks every time so there is not one workbook that the
users will always
use. However, I take your point that importing modules into
people's
personal.xls workbooks is bad program design. Would I
therefore be better to
have a workbook with the sole purpose of containing common
macros that opens
on startup?

Thanks
Andy

"Chip Pearson" wrote:

There is no way with conditional compilation to determine
whether
a userform exists. Why are you assuming that the form should
be
in the user's personal.xls workbook? This is bad program
design.
Personal.xls is, by definition, where users put the own
personal
code. Why don't you put the form in your workbook, so you can
be
assured that it exists.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Andy" wrote in message
...
Hi All

I have a macro that makes use of a UserForm for gathering
data
from the
user. While the userform should always exist on the users'
machines this
might not always be the case. Is anybody aware of a way of
checking to see
if a UserForm exists in the Personal.xls workbook so I can
handle such
instances? If it doesn't then there is obviously a compile
error so I have
had a look at the #const and #if... directives but can't
figure
it out.

Thanks

Andy






Reply
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
Exist or Not. ldiaz Excel Discussion (Misc queries) 3 September 6th 06 09:31 PM
Am I Looking For Something That Doesn't Exist? seanryann Excel Discussion (Misc queries) 11 April 1st 06 06:10 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM
Access from add_in userform to main template userform.... Ajit Excel Programming 1 November 18th 04 05:15 PM


All times are GMT +1. The time now is 08:57 AM.

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

About Us

"It's about Microsoft Excel"