Sort
Profile photo for David Lee

This should do it. This is written in VBScript, not VBA. The reason for that is that Office applications don't have a built-in means of scheduling macros/scripts to run. The best way to accomplish that is to write the script in VBScript and use Windows Task Scheduler to run the script at the desired time.

Follow these instructions to use this solution.

1. Open Notepad
2. Copy the code and paste it into Notepad
3. Edit the code per the comments I included in it
4. Save the file with a .vbs extension
5. Using Windows Task Scheduler, create a new task.
6. Set the task to run at whatever in

This should do it. This is written in VBScript, not VBA. The reason for that is that Office applications don't have a built-in means of scheduling macros/scripts to run. The best way to accomplish that is to write the script in VBScript and use Windows Task Scheduler to run the script at the desired time.

Follow these instructions to use this solution.

1. Open Notepad
2. Copy the code and paste it into Notepad
3. Edit the code per the comments I included in it
4. Save the file with a .vbs extension
5. Using Windows Task Scheduler, create a new task.
6. Set the task to run at whatever interval you need
7. Set the task to run this script
8. Set the task to run under your account

  1. '--> Create some constants 
  2. Const olMailItem = 0 
  3. 'On the next line edit the path to the Excel workbook 
  4. Const WORKBOOK_PATH = "C:\Users\David\Documents\Testing\Test.xlsx" 
  5. 'On the next line edit the name of the sheet within the workbook that contains the mail info 
  6. Const WORKSHEET_NAME = "Sheet1" 
  7. 'On the next line edit the path to the folder containing the file attachments 
  8. Const ATTACHMENT_FOLDER = "C:\Users\David\Documents\Testing" 
  9.  
  10. '--> Define some variables 
  11. Dim olkApp, olkSes, olkMsg, excApp, excWkb, excWks, lngRow, objFSO, objFol, objFil, objShl, strApp, strSig 
  12.  
  13. '--> Initialize some variables 
  14. Set objFSO = CreateObject("Scripting.FileSystemObject") 
  15. Set objshl = CreateObject("WScript.Shell") 
  16. strApp = objShl.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Signatures\" 
  17.  
  18. '--> Main routine 
  19. 'Connect to Outlook 
  20. Set olkApp = CreateObject("Outlook.Application") 
  21. Set olkSes = olkApp.GetNamespace("MAPI") 
  22. olkSes.Logon olkApp.DefaultProfileName 
  23.  
  24. 'Connect to Excel 
  25. Set excApp = CreateObject("Excel.Application") 
  26. Set excWkb = excApp.Workbooks.Open(WORKBOOK_PATH) 
  27. Set excWks = excWkb.Worksheets(WORKSHEET_NAME) 
  28.  
  29. 'Read the spreadsheet and create the messages 
  30. For lngRow = 1 To excWks.UsedRange.Rows.Count 
  31. If excWks.Cells(lngRow, 6).Value <> "" Then 
  32. Set objFil = objFSO.OpenTextFile(strApp & excWks.Cells(lngRow, 6).Value & ".htm") 
  33. strSig = objFil.ReadAll 
  34. objFil.Close 
  35. End If 
  36. Set olkMsg = olkApp.CreateItem(olMailItem) 
  37. With olkMsg 
  38. .Subject = excWks.Cells(lngRow, 1) & " " & Date 
  39. .To = Replace(excWks.Cells(lngRow, 2).Value, ",", ";") 
  40. .Cc = Replace(excWks.Cells(lngRow, 3).Value, ",", ";") 
  41. .HTMLBody = excWks.Cells(lngRow, 4).Value & "<br>" & strSig 
  42. If LCase(excWks.Cells(lngRow, 5).Value) = "yes" Then 
  43. Set objFol = objFSO.GetFolder(ATTACHMENT_FOLDER) 
  44. For Each objFil In objFol.Files 
  45. .Attachments.Add objFil.Path 
  46. Next 
  47. End If 
  48. .Display 
  49. End With 
  50. Next 
  51.  
  52. '--> Clean-up 
  53. 'Close Excel 
  54. excWkb.Close False 
  55. Set excWks = Nothing 
  56. Set excWkb = Nothing 
  57. Set excApp = Nothing  
  58.  
  59. 'Close Outlook 
  60. Set olkMsg = Nothing 
  61. Set olkSes = Nothing 
  62. Set olkApp = Nothing  
  63.  
  64. 'Delete other object 
  65. Set objFSO = Nothing 
  66. Set objFol = Nothing 
  67. Set objFil = Nothing  
  68. Set ObjShl = Nothing  
  69.  
  70. WScript.Quit 

Note: The OP contacted me asking for one change. Column F of the spreadsheet contains the name of a signature they want applied to each message. I modified the code to check column F for a value. If it's not blank, then the code will read the signature in and apply it to the message. If it is blank, then the code does not apply a signature. The name of the signature must match that of a signature defined in Outlook.

Profile photo for Frank Elliott

Macros are user-generated programs used to perform simple repetitive tasks. After you create a macro, you can run it whenever you need it.

For example:

  1. You record your keystrokes doing a Search in the Inbox for messages with Subject field text “new order” (because the web page where new orders are generated via email uses that phrase as default Subject text. Then,
  2. x times per day, you run your macro to find messages with new orders.

Try googling Outlook macro tutorials for more explanation and elementary examples.

Profile photo for David Lee

No. Outlook does not have a macro recording feature.

Profile photo for Les Black

Updates of what? You can create the code for sending your current document by starting the Macro Recorder then File Menu → Share → Attach a copy and then OK. The code will, now, be in your VBA IDE.

Profile photo for Alan Mellor

Macros are text substitutions.

The significance is that the programming language “does not know about them”.

They are more like a shortcut in your text editor, where you specify “everytime you see the text THIS_IS_MY_MACRO, cut it it and replace it with “some other text”.

By the time the programming language gets to parsing the source code file, the macro replacements have all been done. The original text THIS_IS_MY_MACRO is not presented to the compiler at all, and so it has no syntax rules around it. That’s what I mean by “the language does not know about it”.

Contrast this to say using a consta

Macros are text substitutions.

The significance is that the programming language “does not know about them”.

They are more like a shortcut in your text editor, where you specify “everytime you see the text THIS_IS_MY_MACRO, cut it it and replace it with “some other text”.

By the time the programming language gets to parsing the source code file, the macro replacements have all been done. The original text THIS_IS_MY_MACRO is not presented to the compiler at all, and so it has no syntax rules around it. That’s what I mean by “the language does not know about it”.

Contrast this to say using a constant value of a variable; the language does know about variables and their rules, and could tell you “error: should be a number there, but you supplied a text string”. This cannot happen for macros. They are a simpler beast

Profile photo for Harneet Singh

Word macros are one-click wonders that let you program complex procedures to launch at your bidding. Here are a few examples to get you started. One creates your company letterhead; the second one inserts pre-formatted tables; and the third one defines and designs custom book formats.

Macro-based malware is on the rise and we understand it is a frustrating experience for everyone. To help counter this threat, we are releasing a new feature in Office 2016 that blocks macros from loading in certain high-risk scenarios.

When you opens the Word document, it opens in Protected View. Protected View is

Word macros are one-click wonders that let you program complex procedures to launch at your bidding. Here are a few examples to get you started. One creates your company letterhead; the second one inserts pre-formatted tables; and the third one defines and designs custom book formats.

Macro-based malware is on the rise and we understand it is a frustrating experience for everyone. To help counter this threat, we are releasing a new feature in Office 2016 that blocks macros from loading in certain high-risk scenarios.

When you opens the Word document, it opens in Protected View. Protected View is a feature that has been available in Word, Excel, and PowerPoint since Office 2010. It is a sandboxed environment that lets a user read the contents of a document. Macros and all other active content are disabled within Protected View, and so your email updates wont work.

This feature relies on the security zone information that Windows uses to specify trust associated with a specific location. For example, if the location where the file originates from is considered the Internet zone by Windows, then macros are disabled in the document. Users with legitimate scenarios that are impacted by this policy should work with their enterprise administrator to identify alternative workflows that ensure the file’s original location is considered trusted within the organization.

Profile photo for Raman Sama

Hi,

A macro (which stands for "macro-instruction") is a programmable pattern which translates a certain sequence of input into a preset sequence of output.

Macros can be used to make tasks less repetitive by representing a complicated sequence of keystrokes, mouse movements, commands, or other types of input.

Profile photo for Jonathan Keith

What you are looking for is a Mail Merge, a built-in function of the Microsoft Office Suite that uses Word for composition and many data sources (Excel, Access, CSV, SQL, etc.) for the variable content of each output, which can be e-mail or other document formats. Please search for Mail Merge or just open Word, select Mailings, and follow the wizard.

Here are the details.

Source Data file:

Formatting for Date columns:

Word file, used to compose the e-mail and import the data:

Filter the data (in Word) to limit e-mails to people with parking spaces:

Format the "Date" value as "Monday, 28 March."

Fina

What you are looking for is a Mail Merge, a built-in function of the Microsoft Office Suite that uses Word for composition and many data sources (Excel, Access, CSV, SQL, etc.) for the variable content of each output, which can be e-mail or other document formats. Please search for Mail Merge or just open Word, select Mailings, and follow the wizard.

Here are the details.

Source Data file:

Formatting for Date columns:

Word file, used to compose the e-mail and import the data:

Filter the data (in Word) to limit e-mails to people with parking spaces:

Format the "Date" value as "Monday, 28 March."

Final output. Once formatted to your liking, just select Mailings > Finish & Merge > Send EMail Messages. Enter the Subject Line and hit OK.

Comments: I'll leave it to you to figure out how to handle when someone does not get a parking space each day. Since we are already filtering e-mails based on whether they get a spot during the week at all, my suggestion would be to create a separate e-mail for each day of the week and filter for that day only. People who didn't get a parking space would not get an e-mail, and others would only receive e-mails for the days that they actually had a space.

Make sense?

Profile photo for Jagjit Singh

From Google search: How do you insert a field that will automatically update in Word?

Automatically Updating Fields and Links

  1. Choose Options from the Tools tab. Word displays the Options dialog box.
  2. Make sure the General tab is selected. (See Figure 1.)
  3. Click the Update Automatic Links at Open checkbox.
  4. Click on OK.

More here: Word macros: Three examples to automate your documents

Profile photo for Vladislav Zorov

Macros allow you to extend a programming language with new syntax. Roughly what functions are to your program’s data, macros are to your program’s code.

For some examples, check out:


I hear that you can’t really do macros in JavaScript

That’s not exactly true!

If you’re willing to put up with using an external tool and JavaScript’s irregular notation, there’s SweetJS. Near the end of that tu

Macros allow you to extend a programming language with new syntax. Roughly what functions are to your program’s data, macros are to your program’s code.

For some examples, check out:


I hear that you can’t really do macros in JavaScript

That’s not exactly true!

If you’re willing to put up with using an external tool and JavaScript’s irregular notation, there’s SweetJS. Near the end of that tutorial they show you how to add the class keyword to JS.

Note that macros in general aren’t very convenient in non-Lisps, for many reasons (the aforementioned irregular notation, the lack of a compiler API for macro writers, the lack of standard library functions for macro writers, etc.) - so if your only experience is with SweetJS, you’ll probably be left with the wrong impression about the power and usefulness of macros.

In Lisp, macros are pretty much as easy to do as functions - just like how normally you don’t think twice about defining a function to deal with some repeated operation on data, in Lisp you don’t think twice about defining a macro to deal with some boilerplate in your code (for example as soon as you figure out that most of your functions will need to log when they get called, or check permissions of some user object or something, you just add a new function definition statement that does that automatically, and switch to using that instead of defun).

Profile photo for David Lee

I use Outlook macros for two things.

  1. As Diane Poremsky noted, I use them to simplify multi-step tasks.
  2. I use them to add functionality that’s not built into Outlook.
Profile photo for Mark Miller

Macros are small code generators. You set up some code in them to be placed into a stream of computation. They can be parameterized so that you can change somewhat the code that’s generated.

Macros are placed in the code stream, using the macro name, and whatever parameters are desired. They are expanded at some point (during loading, interpretation, compilation, execution, etc.), which means that the parameters are applied to the code in the macro, and the resulting code is substituted in place of the aforementioned macro name and parameters.

The evaluation of macros can be recursive as well. S

Macros are small code generators. You set up some code in them to be placed into a stream of computation. They can be parameterized so that you can change somewhat the code that’s generated.

Macros are placed in the code stream, using the macro name, and whatever parameters are desired. They are expanded at some point (during loading, interpretation, compilation, execution, etc.), which means that the parameters are applied to the code in the macro, and the resulting code is substituted in place of the aforementioned macro name and parameters.

The evaluation of macros can be recursive as well. So, the code inside a macro can refer to other macros. This means that as the macro is expanded, if there are other macros cited in the macro code, the same process occurs in situ during the expansion: The cited macro is expanded (with parameters) inside the outer macro expansion, and then if there are any macros cited inside that, the process repeats. The process stops when there are no more embedded macros to expand.

As an example, I talked about a C macro I used many years ago at Mark Miller's answer to What is the most complex line of C code you have created or encountered?

C/C++ macros are expanded prior to compiling your C/C++ code. When you run a C or C++ compiler, a piece of software called the preprocessor is run over your code, and it substitutes C/C++ code for the directives in your source code before the C/C++ compiler sees it. This allows any macros to be expanded into that code stream, and the end result of those expansions is all the compiler sees. The preprocessor responds to any directive in the code preceded by a hash (‘#’), like #include <stdio.h>.

In Common Lisp, macros are expanded at various times, during loading, compiling, or evaluation (execution). I only know about the last case. One of the classic macros in Lisp is IF, which carries out if-then-else logic. The reason for this is in order for Lisp to carry out that logic, one needs to change how the Lisp evaluator processes the IF expression. That’s the primary use for Lisp macros, to change evaluator behavior. The nice thing about Lisp macros is they look like the rest of the non-macro code, since all code in Lisp uses the same syntax. This simplifies code analysis quite a bit.

It’s likely that Lisp popularized macros, since it’s hard to do much in Lisp without that capability, and the language has been around since the late ‘50s. There are many things that Lisp popularized, including if-then-else logic, from what I’ve heard.

As for macros in JavaScript, I don’t know, since I haven’t worked with it much. In my experience, and in what I’ve read, I haven’t seen any signs of macros in the language.

Profile photo for Aditya Sengupta

Quora User gave an Ignite talk (not TED) in September 2009 that fits the description in your question:

http://www.hilarymason.com/blog/ignitenyc-the-video/

Your response is private
Was this worth your time?
This helps us sort answers on the page.
Absolutely not
Definitely yes
Profile photo for Sam Don

Boomerang is a great tool that reminds you to follow up on notes. Works well with a gmail account, not sure about other email clients.

Also offers a customized time lapse before sending you a reminder.

Profile photo for Quora User
  • Macro are like short functions in C, that when called, the code gets expanded at the point of invocation. In contrast to a normal function, a macro doesn’t create a stacktrace.
  • Notice in the following example that max is not a function, but a C Macro.
  • Macros in C are defined using the define keyword prefixed by the # symbol, which tells the compiler that its a preprocessor directive.
  • Furthermore, macros need to be declared globally on the top of the main().
  1. #include <stdio.h> 
  2. #define max (a > b && a > c && a > d) ? a : ((b > c && b > d) ? b : ((c > d) ? c : d)) 
  3.  
  4. int main() 
  5. { 
  6. int a = 10; 
  7. int b = 20; 
  8. in 
  • Macro are like short functions in C, that when called, the code gets expanded at the point of invocation. In contrast to a normal function, a macro doesn’t create a stacktrace.
  • Notice in the following example that max is not a function, but a C Macro.
  • Macros in C are defined using the define keyword prefixed by the # symbol, which tells the compiler that its a preprocessor directive.
  • Furthermore, macros need to be declared globally on the top of the main().
  1. #include <stdio.h> 
  2. #define max (a > b && a > c && a > d) ? a : ((b > c && b > d) ? b : ((c > d) ? c : d)) 
  3.  
  4. int main() 
  5. { 
  6. int a = 10; 
  7. int b = 20; 
  8. int c = 30; 
  9. int d = 40; 
  10.  
  11. int Max = max; 
  12. printf("\nMax of those 4 numbers is %d", max); 
  13. return 0; 
  14. }  
Profile photo for Ronald 'Ron' J. Ellis

YES and NO…

YES - you can set-up a repeating set of steps by activating the ‘Visual Basic for Applications’ (VBA) for Outlook Add-in at:

[File] → [Options] → [Add-ins] as shown below:

Then continue by reviewing Microsoft’s extensive guideline at:

NO - The use of VBA inside Outlook is not exactly like the traditional idea of a Macro. The folks at ‘Launch Excel’, a website devoted to helping Excel users, differentiate VBA and Macros as follows:

Microsoft VBA is the programming language that Excel Macros are recorded in. VBA stands for “Visual Basic f

YES and NO…

YES - you can set-up a repeating set of steps by activating the ‘Visual Basic for Applications’ (VBA) for Outlook Add-in at:

[File] → [Options] → [Add-ins] as shown below:

Then continue by reviewing Microsoft’s extensive guideline at:

NO - The use of VBA inside Outlook is not exactly like the traditional idea of a Macro. The folks at ‘Launch Excel’, a website devoted to helping Excel users, differentiate VBA and Macros as follows:

Microsoft VBA is the programming language that Excel Macros are recorded in. VBA stands for “Visual Basic for Applications”. With VBA you can create visual basic macros for Excel.

If you can record Macros with the Macro recorder, why would you want to use VBA? The truth is that while the Macro recorder is simple to use, it doesn’t create nice code and it can only record straightforward tasks.

VBA allows you to add brains to your macros and turn them into intelligent programs, for example you can ask the user to type in their name and store that in your program. VBA allows you to take advantage of features that can’t be accessed through the standard user interface.

From: What every Excel user needs to know about Macros and VBA in Excel

VBA is Microsoft’s powerful programming tool that applies to all the Office applications. You might begin to find out more about it at:

Profile photo for David Lee

Unlike the other Office apps, Outlook does not have a macro recorder. You have to write your macros by hand in VBA (Visual Basic for Applications). To create a macro

  1. Open the VBA editor (ALT+F11)
  2. Add a module
  3. Write your macro
Profile photo for Quora User

It's a text substitution mechanism, inserted in the preprocessor of C compiler that enable a programmer write a repetitive code, or constants, or keys for others preprocessor directives once.

Profile photo for Zoltan Boszormenyi

Mostly the same as in assemblers, like in Microsoft’s MASM.

It is a pre-defined symbol with or without parameters. You can create your own macros with the #define pre-processor directive. When you use the macro, its value (plus the actual parameters) are substituted at the location you use it.

Possible use cases of macros:

  • Replace magic constants with names. You can’t underestimate the power of this one for later debugging, or actually the lack of needing it if you do it properly. You have to type a little more but you get back a lot more in readability. E.g.:

    #define N_VALUES 5
    int values[N_VAL

Mostly the same as in assemblers, like in Microsoft’s MASM.

It is a pre-defined symbol with or without parameters. You can create your own macros with the #define pre-processor directive. When you use the macro, its value (plus the actual parameters) are substituted at the location you use it.

Possible use cases of macros:

  • Replace magic constants with names. You can’t underestimate the power of this one for later debugging, or actually the lack of needing it if you do it properly. You have to type a little more but you get back a lot more in readability. E.g.:

    #define N_VALUES 5
    int values[N_VALUES], i;

    for (i = 0; i < N_VALUES; i++) …
  • Replace repeated code patters (sometimes pretty complex ones) with macros with parameters. It can save you a lot of typing and adds readability. Like in the case of a singly-linked list:

    /* list_t is a structure with ->next and ->data pointers */
    #define foreach_list(list, x) \
    (x = list; x; x = x->next)

    list_t mylist, element;
    foreach_list(mylist, element) {
    /* process on element->data */

    }
  • Coupled with #define, #ifdef … #else … #endif, you can use conditionally compiled-in code. One such example is the assert() macro defined in the <assert.h> header.
  • C compilers allow using variadic macros, i.e. ones with variable length parameter list. With conditional #defines, you can use it for conditionally compiled in printout, e.g. for debug builds, or in any other case when the macro’s value contains a variadic function.
  • Mess with other people’s head by redefining obvious functions or types.

Macros in C are string replacements commonly used to define constants.

For example:-

#define MAX 1000

It sets the value of identifier MAX to 1000 and whenever you want to use 1000 in your program you can use MAX instead of writing 1000.

Similarly ,

#define PI 3.1415926

Whenever you have to use value of pi in your code you can simply write PI instead of writing lengthy value of pi again and again.

Basically macros are one of the Preprocessor directives available in C.Macro substitution is a process where an identifier in a program is replaced by a predefined string.

The macro definition takes the follo

Macros in C are string replacements commonly used to define constants.

For example:-

#define MAX 1000

It sets the value of identifier MAX to 1000 and whenever you want to use 1000 in your program you can use MAX instead of writing 1000.

Similarly ,

#define PI 3.1415926

Whenever you have to use value of pi in your code you can simply write PI instead of writing lengthy value of pi again and again.

Basically macros are one of the Preprocessor directives available in C.Macro substitution is a process where an identifier in a program is replaced by a predefined string.

The macro definition takes the following form:

#define identifier string

If this statement is included in the program at the beginning ,then the preprocessor replaces every occurrence of the identifier in the source code by the string .

The keyword #define is written just as shown, followed by the identifier and a string with at least one blank space between them. The definition is not terminated by semicolon. The string may be any constant/expression while the identifier must be a valid C name.

There are different type of macro substitution.The most common forms are:-

  1. Simple macro substitution(simple string replacements to define constants):-

#define M 5

#define COUNT 10

etc.

2. Argumented macro substitution(this permits us to define more complex and more useful forms of replacements):-

It takes the form:-

#define identifier(f1,f2,..,fn) string

for example, #define CUBE(x) (x*x*x)

if the following statement appear in the prog.-

volume=CUBE(side);

then the preprocessor will expand this statement to:

volume=(side*side*side);

3. Nested macro substitution (we can also use one macro in the definition of another macro):-

for example:-

#define SQUARE(x) (x*x)

#define CUBE (SQUARE(x)*(x))

Also,

#define M 5

#define N (M+1)

#define MAX(M,N) ((M>N)?M:N)

Undefining a Macro:-

A defined macro can be undefined ,using the statement-

#undef identifier

This is useful when we want to restrict the definition only to a particular part of the program.

Thats all i know about Macros. I hope you get the clarity .If still you have any doubts feel free to comment below.

Profile photo for David Lee

Assuming that “Date” is immediately followed by a space and then the 8 character date, then this should get the job done. I’m assuming you know how to add macro code to Outlook and set the rule to call it.

  1. Sub MyRule(olkMsg As Outlook.MailItem) 
  2. 'On the next line edit the path to the text file you want to write the date to. If the file does not exist, then the script will create it for you. 
  3. Const FILE_PATH = "c:\users\david\documents\testit.txt" 
  4. Const ForAppending = 8 
  5. Dim objFSO As Object, objFil As Object, strTmp As String 
  6. strTmp = FindString(olkMsg.Body, "Date .{8}") 
  7. If strT 

Assuming that “Date” is immediately followed by a space and then the 8 character date, then this should get the job done. I’m assuming you know how to add macro code to Outlook and set the rule to call it.

  1. Sub MyRule(olkMsg As Outlook.MailItem) 
  2. 'On the next line edit the path to the text file you want to write the date to. If the file does not exist, then the script will create it for you. 
  3. Const FILE_PATH = "c:\users\david\documents\testit.txt" 
  4. Const ForAppending = 8 
  5. Dim objFSO As Object, objFil As Object, strTmp As String 
  6. strTmp = FindString(olkMsg.Body, "Date .{8}") 
  7. If strTmp <> "Not found" Then 
  8. strTmp = Mid(strTmp, 6) 
  9. Set objFSO = CreateObject("Scripting.FileSystemObject") 
  10. If Not objFSO.FileExists(FILE_PATH) Then 
  11. Set objFil = objFSO.CreateTextFile(FILE_PATH) 
  12. Else 
  13. Set objFil = objFSO.OpenTextFile(FILE_PATH, ForAppending) 
  14. End If 
  15. objFil.WriteLine strTmp 
  16. objFil.Close 
  17. End If 
  18. Set objFil = Nothing 
  19. Set objFSO = Nothing 
  20. End Sub 
  21.  
  22. Function FindString(strText As String, strFind As String) As String 
  23. Dim objRegEx As Object, colMatches As Object, objMatch As Object 
  24. Set objRegEx = CreateObject("VBscript.RegExp") 
  25. With objRegEx 
  26. .IgnoreCase = False 
  27. .Global = True 
  28. .Pattern = strFind 
  29. Set colMatches = .Execute(strText) 
  30. End With 
  31. If colMatches.count > 0 Then 
  32. Set objMatch = colMatches.Item(0) 
  33. FindString = objMatch.value 
  34. Else 
  35. FindString = "Not found" 
  36. End If 
  37. Set objRegEx = Nothing 
  38. Set colMatches = Nothing 
  39. Set objMatch = Nothing 
  40. End Function 
Profile photo for Paramdeep Singh

Using Excel, you can use the Outlook Application to Send Emails. I have written a simple VBA Application, that does the following:

If someone receives an email and then this macro automatically sends the email to any id you want with attachment that you want to send. I have defined 3 fields in the Excel: "from", "subject" and "body".

The code would work, if you run the function called StartSendingEmails in module 1.

You can create a new module and copy past the following text. In my excel sheet

Option Base 1
Option Explicit
Public check As New OLAPP

Public Sub StartSendingEmails()
Dim newOL As Out

Using Excel, you can use the Outlook Application to Send Emails. I have written a simple VBA Application, that does the following:

If someone receives an email and then this macro automatically sends the email to any id you want with attachment that you want to send. I have defined 3 fields in the Excel: "from", "subject" and "body".

The code would work, if you run the function called StartSendingEmails in module 1.

You can create a new module and copy past the following text. In my excel sheet

Option Base 1
Option Explicit
Public check As New OLAPP

Public Sub StartSendingEmails()
Dim newOL As Outlook.Application
Set newOL = New Outlook.Application

Dim newItem As MailItem
Set newItem = check.myOlApp.CreateItem(olMailItem)

Page on NewItem = Range("from").Value
newItem.Subject = Range("Subject").Value
newItem.Body = Range("Body").Value
newItem.Send

End Sub


This Module is Calling a new Instance of a class called OLAPP. The code for OLAPP is:


Public WithEvents myOlApp As Outlook.Application
Public WithEvents myOlItems As Outlook.Items

Private Sub Class_Initialize()
Set myOlApp = New Outlook.Application
Set myOlItems = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub


Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

End Sub

Private Sub myOlApp_Startup()
MsgBox ("Start")
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
Dim nMail As MailItem
Dim newExcel As Workbook
On Error Resume Next
Set nMail = Item
On Error GoTo 0

If nMail Is Nothing Then Exit Sub

Dim nAtt As Attachment
On Error Resume Next
Set nAtt = nMail.Attachments(1)
On Error GoTo 0

If Not nAtt Is Nothing Then
If UCase(Right(nAtt.Filename, 4)) = "XLSX" Or UCase(Right(nAtt.Filename, 4)) = "XLSM" Or UCase(Right(nAtt.Filename, 3)) = "XLS" Then
nAtt.SaveAsFile Application.ThisWorkbook.Path & "\" & nAtt.DisplayName
End If
End If

If nMail.Subject <> Range("Subject").Value Then
Dim newItem As MailItem
Set newItem = myOlApp.CreateItem(olMailItem)
Page on NewItem = Range("To").Value
newItem.Subject = nMail.Subject

newItem.Body = nMail.SenderName
newItem.Send

End If
End Sub

Profile photo for Ian Hutcherson

It sends a “Reply to All" to all visible recipients of the email being replied to. That is everyone in the To:” field and also everyone in the “CC:” field. It does not send anything to anyone who may have been in the “BCC:” field because it doesn't know who was BCC'ed in or it wouldn't be a “blind copy".

Profile photo for Manish Shori

Automating tasks in Excel using macros can be incredibly helpful.

Using VBA Macros to Send Email Automatically Based on Cell Value:

Suppose you want to trigger an email when a specific condition is met e.g. an amount in a cell exceeds a certain level.

Open your Excel workbook

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

In the VBA editor, insert the following code into the relevant worksheet’s code window. For this right-click on the sheet and select “View Code

Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next

If Target.Cells.Count > 1 Then Exit Sub

If

Automating tasks in Excel using macros can be incredibly helpful.

Using VBA Macros to Send Email Automatically Based on Cell Value:

Suppose you want to trigger an email when a specific condition is met e.g. an amount in a cell exceeds a certain level.

Open your Excel workbook

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

In the VBA editor, insert the following code into the relevant worksheet’s code window. For this right-click on the sheet and select “View Code

Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next

If Target.Cells.Count > 1 Then Exit Sub

If Target.Address = "$D$6" And IsNumeric(Target.Value) And Target.Value > 400 Then

Call SendMailOutlook

End If

End Sub

Sub SendMailOutlook()

Dim OutlookApp As Object

Dim MailItem As Object

Dim EmailBody As String

Set OutlookApp = CreateObject("Outlook.Application")

Set MailItem = OutlookApp.CreateItem(0)

EmailBody = "Hello!" & vbNewLine & vbNewLine & _

"Hope you are well. Visit our site Exceldemy."

With MailItem

.To = "recipient@example.com" ' Replace with the actual email address

.Subject = "Send mail based on cell value"

.Body = EmailBody

.Display

End With

Set MailItem = Nothing

Set OutlookApp = Nothing

End Sub

Customize the recipient’s email address, subject and body as needed.

Whenever the value in cell D6 exceeds 400, this macro will automatically create an email in Outlook with the specified content. You’ll need to click the “Send” button to send the email.

Using Formulas to Create Hyperlinks for Email Addresses:

If you prefer a non-macro solution, you can create a hyperlink formula that opens the default email client with a pre-filled email:

Suppose your email addresses are in column C and you want to create a hyperlink in column E. Use the following formula in cell E3 (adjust as needed)

=HYPERLINK("mailto:" & C3 & "?subject=Your%20Subject&body=Your%20Message", "Send email")

The mailto: command opens the default email client with the specified parameters.

Profile photo for Venu Gopalan

If you are uding the Microsoft CDO library then there is an option to send attachments.

Profile photo for David Fox

Just a suggestion before you go and reinvent the wheel: use Microsoft Word’s Mail Merge feature or use Gmail and Google Sheets - Sheets has plugins for what you want to do.

Profile photo for Quora User

Mail is scriptable and you can do what you ask using AppleScript or, if using 10.10 or later, you can use JavaScript for Automation. An AppleScript example:

  1. tell application "Mail" 
  2. set newMessage to make new outgoing message with properties { visible: true, subject: "Important Message from Widget Co!", content: "We've got a new catalog!" } 
  3.  
  4. tell newMessage 
  5. make new to recipient with properties { name: "Joe Consumer", address: "j.consumer@isp.net" } 
  6. end tell 
  7.  
  8. tell content of newMessage 
  9. make new attachment with properties { file name: pathToAttachment } after last paragrap 

Mail is scriptable and you can do what you ask using AppleScript or, if using 10.10 or later, you can use JavaScript for Automation. An AppleScript example:

  1. tell application "Mail" 
  2. set newMessage to make new outgoing message with properties { visible: true, subject: "Important Message from Widget Co!", content: "We've got a new catalog!" } 
  3.  
  4. tell newMessage 
  5. make new to recipient with properties { name: "Joe Consumer", address: "j.consumer@isp.net" } 
  6. end tell 
  7.  
  8. tell content of newMessage 
  9. make new attachment with properties { file name: pathToAttachment } after last paragraph 
  10. end tell 
  11.  
  12. send newMessage 
  13. end tell 
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025