Outlook 2007 Macro to Run a Script From a Contact Form

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I have some codes in my script of the Contact form I created that does some things. Is there a macro that I can create in Module that refers to the specific code in the script and runs it when I run the macro?

Or also, is there a code I put in the Outlook Session area that runs the script code in from a form of the Contact?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
And the script code is run from a commandbutton in the contact form.....so is there a macro that identifies the form of the form of the contact, and runs the commandbutton?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
to call script in the contact form, you need to use a public macro and call it by name - but this only works for useforms. The simple script in "Run Script" form can't be called from outside if i recall correctly. It's kicked off by events, so you could use vba to kick off the event.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
In the past, you gave me the code that creates an email to the contact that is not opened but I highlight the contact. So is there a macro that when I highlight the contact but not open the contact, and then the macro runs a script code that is in the contact I highlight? As the script code only runs if I open the contact and click on a certain commandbutton.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The macros in the View Script (not Run Script, sorry) are not accessible from VBA - they need to be called by actions. You could use a property change (or custom property change) to trigger something. See http://support.microsoft.com/kb/180857/en-us for samples.

Basically, you'd add a custom field top the form, a simple checkbox should work, and use VBA to change it. When it changes, the custom property change is triggered and it triggers whatever you wanted to run. But I'm not sure if the events work with selections or if the form needs to be opened.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Thanks very much....that area won't do it....but, the script code in the contact is run in the contact by a commandbutton.....so do we have macro that identifies the name of the commandbutton in a contact, I select the contact and not open it up, and the macro then effectively clicks that commandbutton?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
any update re the above...as I seems to me that there should be an simple macro that identifies the commandbutton in a contact, I select the contact and not open it up, and the macro then effectively clicks that commandbutton?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
No updates today, had a server go down and spent all day in the server room. :( The problem is the commandbutton code is not exposed outside of the form... that makes it difficult for outlook's VBA to find it.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Got it! However, the code and related commandbutton click are in the form of the contact. So is there a way to run the click somehow from referring to the form and when I highlight the contact? Or anyother way?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I received the following VBA code from someone but it's not clear to me what to put in it etc.......I assume there is a Private Sub Name () and an End Sub words...but don't know what to replace re his words areas.....my Contact Form 1 (which you helped me create!!) is in the Personal FormsLibrary ...and don' know what Required Input Control Name means? Any answers please as I just need to the full code to copy and paste it and run it

Load [LibraryName].Forms("Contact Form 1")

With Forms("Contact Form 1")
.[Required Input Control Name].Value = Selection
.CommandButton1_Click

End With

Forms("Contact Form 1").Unload
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You'd either put it in a sub and call it using your code or put it in your code where you want to call it up.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Thanks. I don't understand what you said. Can give me the details of what to do please ;)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Decide where you want to bring up the code - probably right before you do whatever with the selected contact, and add the lines.

Load [LibraryName].Forms("Contact Form 1")
With Forms("Contact Form 1")
.[Required Input Control Name].Value = Selection
.CommandButton1_Click
End With
Forms("Contact Form 1").Unload

library name is where it's stored - what you see in the Look in box in the choose forms dialog (i'm not sure if you need the folder name - I've never used the library in code). Use the display name (again, from the choose forms dialog) in the other fields and the name of the control you want to select.

*Because you are in contacts already, you should only need the entry in the lookin box.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Here are the words I have found, so please put them where they need to be as I have no idea what to do still The Contact Form 1 is in the Personal Forms Library of choosing a form......the commandbutton name is CommandButton4 ....and what do I put at the top and bottom re Sub?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It's my deadline day and I'm still working on the deadline. :( So no update today. Sorry.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Put this at the top of the macro that you are are using to call the form

Load ["Personal Forms Library"].Forms("Contact Form 1")
With Forms("Contact Form 1")
.[Command Button].Value = Selection
.CommandButton4_Click
End With

this at the end before end sub.
Forms("Contact Form 1").Unload

If you just need to call the macro in the form, and are doing anything else with it, then just wrap it with Sub / end sub.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Thanks very much.....what macro to use to call the form? Not sure what to do...sorry.....the code in the script of the contact form is the thing I want to make happen on the contact I select.....any thoughts please?
 

Top