programmatically opening a form

G

Guest

Hello,
I have a form in my Personal Forms library that I use quite a bit. Is there
a way to open the form with a macro? If so, I could put a button on my
toolbar to run the macro so that the form would open on one click instead of
having to do choose form, then scroll to personal forms library, double click
on the form, etc.

I've used VBA in Excel and Access, but never with Outlook. I would think
there would be something like:

sub OpenMyForm()

Application.PersonalFormsLibrary.Form("MyForm").Open

end sub

But I haven't been able to figure out what any of the objects, properties or
methods might be called.

If anyone has any suggestions, please let me know.
 
H

Hollis Paul

sub OpenMyForm()

Application.PersonalFormsLibrary.Form("MyForm").Open

end sub

But I haven't been able to figure out what any of the objects, properties or
methods might be called.

If anyone has any suggestions, please let me know.
Good try for top of the head speculation. But you can find the answer by
invoking the VBA coding environment (ALT-F11) in Word 2003, bring up the Object
Browser (F2) and poke around in the Word Object Model, itself.

Your biggest problem will be creating a toolbar as a COM add-in.

But, if you are willing to run it from the macro list, then the following
article will give you a start:

Automating Tip Capture with Office Systems 2003 - Part 2
http://msmvps.com/blogs/obts/pages/71693.aspx

There is a Part 1, also, but the discussion of the various bits of code is in
Part 2.
 
G

Guest

Sue,
Thank you very much, I was able to adapt the code on that page and make it
work. However, in order to get it to work, I had to publish the form to a
folder (I used Outbox since it's a preformatted mail item that gets filled
out and sent) and then specify olFoldersOutbox in the GetDefaultFolder
object. I never could figure out a way to tell the code that the form lived
in the Personal Forms Library. I tried using olPersonalRegistry when the
MyFolder variable was set, but that gave me a run-time error.
Is there any way that I can make the code pull the form from the Personal
Forms Library so that I don't have to keep this particular form in a
different place from the rest? I forgot to mention eariler, but Outlook2003,
WinXPPro. Here is the code that works pulling the form from the Outbox:

======
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderOutbox)
Set myItems = myFolder.Items
Set myItem = myItems.Add("IPM.Note.ToDo")
myItem.Display
=======

Any suggestions would we very welcome.

Thanks again for all the help.

Mike
--
Mike Lee
McKinney,TX USA


Sue Mosher said:
Use the Add method on the target folder's Items collection. See http://www.outlookcode.com/d/launchform.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

What you've done is quite correct. It is not necessary to tell Outlook where the form is published. Outlook will automatically look in the available form libraries in sequence. The target folder must be the folder which you want to use to store the item. For a message, either the Drafts folder or the Outbox would be appropriate.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Thanks Sue. I'm still kind of confused, however. When I had the form in the
Personal Forms Library, the macro didn't open the form no matter what I used
as the default folder. It just opened a standard mail item, as if I had
clicked on New Mail Message. The only way I could get the actual form to
open was to publish it to the Outbox and use the Outbox as the default folder.
This works, but now I have a form that's not in the Forms Library, and I
sort of like to keep them all in the same place, if that makes any sense.
 
S

Sue Mosher [MVP-Outlook]

That could hve been a problem with the form and how it was published. If you checked the "send form definition with item" box, for example, you might see that behavior.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Ahhh...yes, that box is checked. That would explain it.

Thanks again for all the help (and for putting up with my follow up
questions).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top