Script to Macro in Module

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I found these two different ways to have a commandbutton in a contact run a code from the script that runs a macro from a module. Do either if these do it?

sub CommandButton1_click

call module1.macroname()

end sub

sub CommandButton1_click

macroname

end sub
 
The macroname only version is the shorthand version - using call is optional. Using the module name eliminates ambiguous names - if you happen to have 2 with the same name, it finds the correct one. Either should work fine.
 
I just did

sub CommandButton5_click

call module7.E_Mails_From_Lou_Stoler_and_Catch_Ups()

end sub

and there is error "object module7 required"

and then I did:

sub CommandButton5_click

E_Mails_From_Lou_Stoler_and_Catch_Ups()

end sub

and there errro is "type mismatch E_Mails_From_Lou_Stoler_and_Catch_Ups"

Any way to fix these?
 
try the second without the () - that is usually reserved for functions or when you need to pass values to the macro.
 
sub CommandButton5_click

E_Mails_From_Lou_Stoler_and_Catch_Ups

end sub

Same errror "type mismatch E_Mails_From_Lou_Stoler_and_Catch_Ups"
 
type mismatch means there is something that doesn't match - you're asking for a string when it should be a value or something. Does the macro you are calling work fine if you run it on its own?
 
Yes it works fine....i open up the contact, go to macros, click on it, and run it and it does it....this is a macro code you gave me that creates the emai to the contact using a template....and the macro correlates to a userform so when I run the macro, it opens up the combobox from the related userform....

so the key is to create the commandbotton in the contact form thru the script so it runs that macro which opens up the combobox from the related useform...

Anything else to upgrade ??
 
Yeah, this type of macro needs to run from a command button on the ribbon or toolbar.
 
OK....so is there a way that when I put the macro on the quck tool bar of the contact as a part of the form, can I create a commandbotton in a scipt or some other way that when I click on the commandbotton it runs the button from the quck tool bar?
 
And also, instead of using the macro goes to the userfrom, I typed the macro name which is just single macro that creates the email per the template....and it is the same error....
 
so something like this, run in a normal manner

sub runthis()

macroname

end sub

failed too?
 
Where do i put it please and is it another macro or do i add the commandbutton click to it somehow and put in the script?
 
udate please??? I created that macro you just showed me....and when i run that macro, it runs the macroname I put in.....but how do I put that macro in the script so there is a commandbutton to it? I tried it per the standart commandbotton_click thing, and same error re not recognizing the macro
 
Sorry, I played hooky today - i'll try and take a look tomorrow. If the macro is not in the userform, you will need to use Public macros in the module and may need to use the module name.
 
Thanks much....look forward to it being done!!! PS, sent you the codes in a word document.
 
Any update from the Smart Woman???? I need it!!! :):)
 
I found a way to create a code in the Outlook Session as follows and when I run it, it runs the macro of the macro name.

Public Sub runthis()

macroname

End Sub

Then in the Script area of the Contact form, I added the following code and CommandButton6 to the form, and when I click on the CommandButton, it runs the macroname.

Sub CommandButton6_Click

Set myOlApp = CreateObject("Outlook.Application")

myOlApp.runthis

End Sub

Then when I created the same things as second way with runthis1 with a different macroname and a commandbutton 7, when I run the contact from it shows the commandbuttons and the commandbotton7 runs the macro related to the runthis1

But the problem is when I publish this form, and create a new contact from the form, the new contact does not show the commandbutton7 for some reason....

So it seems I found the way to do it, but it is not saving the second commandbutton7 in the contact I create, even though when I click on a new contact to create, both commandbuttons show up, but the commandbutton7 does not save in the contact I create.

Can we fix this?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
J VBS Script (macro) for word to open Outlook template. Outlook VBA and Custom Forms 2
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
L Outlook 2007 Macro to Run a Script From a Contact Form Using Outlook 41
E New Macro/Script needed Using Outlook 5
R Script for simplifying spam control Outlook VBA and Custom Forms 8
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
N Outlook 2021 'Run Script" Rules? Outlook VBA and Custom Forms 4
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
W Designer Form 2013 and Script ? how ? Outlook VBA and Custom Forms 1
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
G Save attachment run a script rule Outlook VBA and Custom Forms 0
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
G Script does not exist Outlook VBA and Custom Forms 0
G Trigger script without restaring outlook Outlook VBA and Custom Forms 7
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
L VB script only runs manually Outlook VBA and Custom Forms 5
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
D.Moore VB script to Digitaly Sign newly created outlook message Outlook VBA and Custom Forms 2
Aussie Rules Run a Script on an Incoming Email OK and then the Email reverts Outlook VBA and Custom Forms 0
D.Moore VBA script fail after Office 365 update Using Outlook 8
M Outlook 2013 Script Assistance - Save Opened Link with Subject Added Outlook VBA and Custom Forms 1
F Script for zip file attachment Outlook VBA and Custom Forms 1
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
Y Outlook 2013 Run A Script Outlook VBA and Custom Forms 4
Z Script to set account? Using Outlook 0
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
J Calling a Public sub-routine from the script editor via VB script Outlook VBA and Custom Forms 4
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
Peter H Williams Enable script containing VBA Outlook VBA and Custom Forms 12
H VB script in outlook form doesn't work anymore Outlook VBA and Custom Forms 2
A Script to fetch data from mails in restricted collection and sending them to excel Using Outlook 1
B Wanting to run a script that will filter any body that has a russian link in it. Outlook VBA and Custom Forms 5
Bri the Tech Guy Registry Tweak to make "Run a Script" Action Available Outlook VBA and Custom Forms 2
V VB script code to save a specific email attachment from a given email Outlook VBA and Custom Forms 14
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
M Subject Line Automation - Trigger Script Delayed Outlook VBA and Custom Forms 2
Q Script to create a pst file for Archiving Using Outlook 1
Vijay Error in rule- Run a script Using Outlook 1
R VBA Script Quick Parts Using Outlook 1
Vijay Run script doesn't work in outlook Using Outlook 1
Q VBA Script to move item in secondary mailbox Outlook VBA and Custom Forms 2
Diane Poremsky Run a Script Rule: Send a New Message when a Message Arrives Using Outlook 2
F Avoid sending duplicate using Outlook script Outlook VBA and Custom Forms 2
oliv- How to Run a Script IN AN ADDIN with Outlook's Rules and Alerts Outlook VBA and Custom Forms 2
L Run a Script Rule doesn't work Using Outlook 5
N Outlook script to forward emails based on senders' address Outlook VBA and Custom Forms 2

Similar threads

Back
Top