<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6329639272790607496</id><updated>2012-01-25T09:13:28.179+05:30</updated><title type='text'>Exploring Excel Macros</title><subtitle type='html'>This blog is dedicated to the knowledge of MS Excel and its most fascinating feature called MACROS.
I'm strongly believe that anything we can think of can be done through excel.
The best way to further enrich our knowledge on this amazing tool is to face more challenges and share the learning with more and more number of people.
Just mail your question to gulthemacroguy@gmail.com and the answers will be posted on this page.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://themacroguy.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6329639272790607496/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://themacroguy.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Gulshan Purswani</name><uri>http://www.blogger.com/profile/14154120268005119468</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6329639272790607496.post-8603195610963566618</id><published>2012-01-25T09:13:00.000+05:30</published><updated>2012-01-25T09:13:28.191+05:30</updated><title type='text'>Create Automatic Index sheet in Excel</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The purpose of this macro is to create an index sheet for your excel file. The index sheet will contain a list of all the worksheets available in the excel file. &lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Steps involved:&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ol style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;Open the excel file where you want to add index sheet&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;Insert a new sheet at the beginning of the file and rename it as “Index”&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;Press Alt+F11&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;A new visual basic window will open, in the left pane (project explorer), select the Index sheet and double click&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;In the right pane, where you can enter the macro commands, there will be 2 drop down boxes.&lt;/li&gt;&lt;li class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;Select “Worksheet” in the first drop down box and select “Activate” in the second drop down box. Thus you are telling the system to run the macro whenever this worksheet is activated.&lt;/li&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-t_z87h09Gjg/Tx95G8MCQCI/AAAAAAAAA5A/RbIAdzf0hbU/s1600/Image2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" gda="true" src="http://3.bp.blogspot.com/-t_z87h09Gjg/Tx95G8MCQCI/AAAAAAAAA5A/RbIAdzf0hbU/s1600/Image2.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;li class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;Paste the below code as it is:&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;Private Sub Worksheet_Activate()&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;Dim wSheet As Worksheet&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;Dim M As Long&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;M = 1&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;With Me&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;.Columns(2).ClearContents&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;.Cells(1, 2) = "INDEX"&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;End With&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;For Each wSheet In Worksheets&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;If wSheet.Name &amp;lt;&amp;gt; Me.Name Then&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;M = M + 1&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;Me.Hyperlinks.Add Anchor:=Me.Cells(M, 2), Address:="", SubAddress:="Start" &amp;amp; wSheet.Index, TextToDisplay:=wSheet.Name&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;End If&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;Next wSheet&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"&gt;End Sub&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ol start="8" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;Save the file and go to the Index sheet. You will notice that the index has been listed in column B.&lt;/li&gt;&lt;div class="separator" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-aArVztaXw0E/Tx95jqYzHbI/AAAAAAAAA5I/ydgl3xZvl34/s1600/Image1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" gda="true" src="http://4.bp.blogspot.com/-aArVztaXw0E/Tx95jqYzHbI/AAAAAAAAA5I/ydgl3xZvl34/s1600/Image1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;li class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;This macro will run everytime you come to this sheet, which effectively means that index will be updated whenever you come to the sheet and you always see the latest list of sheets in that order.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo1; tab-stops: list .5in;"&gt;You can click on any of the sheet names to go directly to that sheet.&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Line by Line analysis of the macro:&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ol style="margin-top: 0in;" type="a"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Private Sub Worksheet_Activate()&lt;/b&gt; - even which triggers the macro.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Dim wSheet As Worksheet&lt;/b&gt; – define the variable which will be used later to identify the individual sheets&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Dim M As Long&lt;/b&gt; – this will be used as a counter and to update the rows in the list one by one.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;M = 1&lt;/b&gt; – initiate the value of M at 1.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;With Me&lt;/b&gt; – start working with the current worksheet where Me refers to the current worksheet, ie. Index sheet.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;.Columns(2).ClearContents&lt;/b&gt; – for the current worksheet, delete the data in column B. This will delete any previously existing index&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;.Cells(1, 2) = "INDEX"&lt;/b&gt; – Enter the value in cell B2 as Index – heading of the list&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;End With&lt;/b&gt; – end working with the current worksheet.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;For Each wSheet In Worksheets&lt;/b&gt; – “For” loop is used to start working with one sheet at a time and continue till all the sheets are done.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;If wSheet.Name &amp;lt;&amp;gt; Me.Name Then&lt;/b&gt; – make sure that the system has not come back to the starting point, (i.e. index worksheet) and to avoid making a reference to index in the index sheet itself&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;M = M + 1&lt;/b&gt; – increase M by 1. this will allow to update the next row in the index instead of overwriting the current row&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Me.Hyperlinks.Add Anchor:=Me.Cells(M, 2), Address:="", SubAddress:="Start" &amp;amp; wSheet.Index, TextToDisplay:=wSheet.Name – &lt;/b&gt;create a hyperlink to the respective worksheet. As we can see, we are using the cell address (M,2) to update the list, this way, the system keeps moving one row down everytime it finds a new worksheet.&lt;b style="mso-bidi-font-weight: normal;"&gt;&lt;/b&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;End If&lt;/b&gt; – end the if condition&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Next wSheet&lt;/b&gt; – At this point, one index entry has been created. Next wsheet will ask the system to go to the next worksheet and follow steps i. to m. again.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;End Sub&lt;/b&gt; – after all the sheets have been indexed. End the macro.&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;This macro is easily available on the internet if you along with a number of other variations. I have only taken one and simplified it for easy understanding.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in;"&gt;Enjoy!!!&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6329639272790607496-8603195610963566618?l=themacroguy.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://themacroguy.blogspot.com/feeds/8603195610963566618/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://themacroguy.blogspot.com/2012/01/create-automatic-index-sheet-in-excel.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6329639272790607496/posts/default/8603195610963566618'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6329639272790607496/posts/default/8603195610963566618'/><link rel='alternate' type='text/html' href='http://themacroguy.blogspot.com/2012/01/create-automatic-index-sheet-in-excel.html' title='Create Automatic Index sheet in Excel'/><author><name>Gulshan Purswani</name><uri>http://www.blogger.com/profile/14154120268005119468</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-t_z87h09Gjg/Tx95G8MCQCI/AAAAAAAAA5A/RbIAdzf0hbU/s72-c/Image2.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6329639272790607496.post-2411951134349320464</id><published>2011-12-22T08:34:00.001+05:30</published><updated>2011-12-22T08:42:16.480+05:30</updated><title type='text'>Excel macro to identify cells containing formulae</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Quite often, we come across large excel sheets with huge volumes of data and a whole lot of formulae. It becomes very tricky to check the validity of each formula.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Even greater is the risk that someone might have deleted a formula and entered a figure manually.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Here is a setup in excel which can help you to identify all the cells having formulae and potentially identify any manual interventions.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;The logic / reasoning follows at the end of the solution.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Open the excel file you want to use&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Select all the cells which you want to cover under this control.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Select Insert &lt;span style="font-family: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-char-type: symbol; mso-hansi-font-family: 'Times New Roman'; mso-symbol-font-family: Wingdings;"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings;"&gt;à&lt;/span&gt;&lt;/span&gt; Name &lt;span style="font-family: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-char-type: symbol; mso-hansi-font-family: 'Times New Roman'; mso-symbol-font-family: Wingdings;"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings;"&gt;à&lt;/span&gt;&lt;/span&gt; Define &lt;span style="font-family: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-char-type: symbol; mso-hansi-font-family: 'Times New Roman'; mso-symbol-font-family: Wingdings;"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings;"&gt;à&lt;/span&gt;&lt;/span&gt; a dialog box will pop up&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-txCAMgOnK_E/TvKbt-mR-zI/AAAAAAAAA3w/XzC7goU9BW8/s1600/untitled.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" rea="true" src="http://3.bp.blogspot.com/-txCAMgOnK_E/TvKbt-mR-zI/AAAAAAAAA3w/XzC7goU9BW8/s1600/untitled.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;In the Names in Workbook field, enter this value: CellHasFormula&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;In the refers to field enter this formula: =GET.CELL(48,INDIRECT(“RC”,FALSE))&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Press Ok to close the dialog box.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-LJTwGf3eZQA/TvKcHHAYraI/AAAAAAAAA38/StfP6z6JGAo/s1600/untitled.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" rea="true" src="http://4.bp.blogspot.com/-LJTwGf3eZQA/TvKcHHAYraI/AAAAAAAAA38/StfP6z6JGAo/s1600/untitled.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;shape id="_x0000_i1026" style="height: 313.5pt; width: 286.5pt;" type="#_x0000_t75"&gt;&lt;imagedata cropbottom="30070f" cropleft="33284f" cropright="14043f" o:title="" src="file:///D:\DOCUME~1\GPI\LOCALS~1\Temp\2\msohtmlclip1\01\clip_image003.png"&gt;&lt;/imagedata&gt;&lt;/shape&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Select Format &lt;span style="font-family: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-char-type: symbol; mso-hansi-font-family: 'Times New Roman'; mso-symbol-font-family: Wingdings;"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings;"&gt;à&lt;/span&gt;&lt;/span&gt; Conditional Formatting &lt;span style="font-family: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-char-type: symbol; mso-hansi-font-family: 'Times New Roman'; mso-symbol-font-family: Wingdings;"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings;"&gt;à&lt;/span&gt;&lt;/span&gt; a dialog box will pop up&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-bvfYkw_nqMs/TvKc3cCvRVI/AAAAAAAAA4I/0LDt45IDqz8/s1600/untitled.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" rea="true" src="http://2.bp.blogspot.com/-bvfYkw_nqMs/TvKc3cCvRVI/AAAAAAAAA4I/0LDt45IDqz8/s1600/untitled.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;shape id="_x0000_i1027" style="height: 186pt; width: 246pt;" type="#_x0000_t75"&gt;&lt;imagedata cropbottom="48141f" cropleft="33030f" cropright="19610f" o:title="" src="file:///D:\DOCUME~1\GPI\LOCALS~1\Temp\2\msohtmlclip1\01\clip_image005.png"&gt;&lt;/imagedata&gt;&lt;/shape&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;In the dialog box, select “Formula is” in the first field.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Type this value in the second field: =CellHasFormula&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-riobwf24HIs/TvKdBvcAnEI/AAAAAAAAA4U/GHNr7TZnL4A/s1600/untitled.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" rea="true" src="http://1.bp.blogspot.com/-riobwf24HIs/TvKdBvcAnEI/AAAAAAAAA4U/GHNr7TZnL4A/s1600/untitled.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;shape id="_x0000_i1028" style="height: 265.5pt; width: 282pt;" type="#_x0000_t75"&gt;&lt;imagedata cropbottom="32492f" cropleft="33261f" cropright="12718f" o:title="" src="file:///D:\DOCUME~1\GPI\LOCALS~1\Temp\2\msohtmlclip1\01\clip_image007.png"&gt;&lt;/imagedata&gt;&lt;/shape&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Click on the format button and select the formatting you want.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Then press ok to exit the dialog boxes.&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;a href="http://1.bp.blogspot.com/-bBcKxFJ7e1w/TvKdSm4BWzI/AAAAAAAAA4g/ZXopFAM-3aw/s1600/untitled.JPG" imageanchor="1" style="clear: left; cssfloat: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" rea="true" src="http://1.bp.blogspot.com/-bBcKxFJ7e1w/TvKdSm4BWzI/AAAAAAAAA4g/ZXopFAM-3aw/s1600/untitled.JPG" /&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;shape id="_x0000_i1029" style="height: 453.75pt; width: 297.75pt;" type="#_x0000_t75"&gt;&lt;imagedata cropbottom="8733f" cropleft="33261f" cropright="11356f" o:title="" src="file:///D:\DOCUME~1\GPI\LOCALS~1\Temp\2\msohtmlclip1\01\clip_image009.png"&gt;&lt;/imagedata&gt;&lt;/shape&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;As you can see below, the fields which contain formula have a different formatting.&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-4o5Mv9sGTPw/TvKd1yARwkI/AAAAAAAAA4s/DrNtiGOpBvg/s1600/untitled.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" rea="true" src="http://2.bp.blogspot.com/-4o5Mv9sGTPw/TvKd1yARwkI/AAAAAAAAA4s/DrNtiGOpBvg/s1600/untitled.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;If you change any of the fields manually or add a formula anywhere, you will see the formatting changes automatically&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;shape id="_x0000_i1030" style="height: 255pt; width: 225pt;" type="#_x0000_t75"&gt;&lt;imagedata cropbottom="46130f" cropleft="32715f" cropright="23301f" o:title="" src="file:///D:\DOCUME~1\GPI\LOCALS~1\Temp\2\msohtmlclip1\01\clip_image011.png"&gt;&lt;/imagedata&gt;&lt;/shape&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;Step by Step analysis:&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;The 2 key steps in this solution are:&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;Naming the range with a formula &lt;span style="font-family: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-char-type: symbol; mso-hansi-font-family: 'Times New Roman'; mso-symbol-font-family: Wingdings;"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings;"&gt;è&lt;/span&gt;&lt;/span&gt; =GET.CELL(48,INDIRECT(“RC”,FALSE))&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;I’m not sure of the roots of this formula, but apparently it is one of the old excel macro commands “Get.Cell” from the time before VB macros were included in excel.&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;Get.Cell is used to retrieve the metadata (or properties) of a cell and use them in the macro.&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;“48” is probably the command used to check whether it is a formula or not. I’m still trying to find what other commands are possible with Get.Cell.&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;“Indirect(“RC”,…” is the normal excel formula which is used to refer to the cell itself.&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;“CellHasFormula” is just a name given to this range. It can be anything you want.&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;div style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;"&gt;Adding Conditional formatting &lt;span style="font-family: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-char-type: symbol; mso-hansi-font-family: 'Times New Roman'; mso-symbol-font-family: Wingdings;"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings;"&gt;è&lt;/span&gt;&lt;/span&gt; In the second stage, we just make a reference to “CellHasFormula” and decide what formatting we want if the cell has a formula.&lt;/div&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;You will notice that we have not written any macros here, but still when you open the file next time, excel will give you a macro warning. That is because we are using “Get.Cell”. You will need to enable macros to be able to use this solution.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6329639272790607496-2411951134349320464?l=themacroguy.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://themacroguy.blogspot.com/feeds/2411951134349320464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://themacroguy.blogspot.com/2011/12/quite-often-we-come-across-large-excel.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6329639272790607496/posts/default/2411951134349320464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6329639272790607496/posts/default/2411951134349320464'/><link rel='alternate' type='text/html' href='http://themacroguy.blogspot.com/2011/12/quite-often-we-come-across-large-excel.html' title='Excel macro to identify cells containing formulae'/><author><name>Gulshan Purswani</name><uri>http://www.blogger.com/profile/14154120268005119468</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-txCAMgOnK_E/TvKbt-mR-zI/AAAAAAAAA3w/XzC7goU9BW8/s72-c/untitled.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6329639272790607496.post-2655510320455446048</id><published>2011-12-12T11:36:00.000+05:30</published><updated>2011-12-12T11:36:32.438+05:30</updated><title type='text'>Excel Macro to automatically send emails to a list of people</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;For your own safety, lets be clear on the below understanding before you start reading or possibly using the below excel solution:&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;You can assume I’m an absolute idiot on MSExcel.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;I have absolutely no formal training of any kind on excel, macros or on programming for that matter.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;I work like a scavenger searching for bits and pieces of macro codes on the net and putting them together to suit my needs.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;There may be bits which I may not understand myself, but there will never be a harmful code posted here as I understand and respect the privacy and integrity of your system.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;If you have improvements or suggestions on the excel solutions posted here, please feel free&amp;nbsp;to post a comment or&amp;nbsp;mail me at &lt;a href="mailto:gulthemacroguy@gmail.com"&gt;gulthemacroguy@gmail.com&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;You can also send in your excel related questions / doubts / requirements on the above email and we can explore the answers together.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Quite often we come across the need to send mails to a number of people automatically. Eg: send personalised greetings, send updates to a list of people, salary details to employees, marks to students and so on.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;There are a number of softwares available on the net which do this, but they are typically paid versions.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;There are other ways to directly using outlook, but those methods need the user to click “OK” every time a message is sent out. This is again for your own security to ensure that virus or spams are not sent without your knowledge. This means you can’t just click a button and forget it.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;I could see the below macro as the most practical way to achieve the desired results.&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Before using the macro, you need to do the following actions:&lt;/div&gt;&lt;ol style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in;"&gt;Create a list with names in Column A and email addresses in column B in an excel sheet. (this macro is for 3 names, but you can add as many as you want)&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in;"&gt;Create a button in excel.&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in;"&gt;Double click on the button and add the below macro code in the window which opens up.&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Private Declare Function ShellExecute Lib "shell32.dll" _&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;ByVal nShowCmd As Long) As Long&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Private Sub CommandButton1_Click()&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;Dim UserName As String&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;UserName = “Macroguy”&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Dim Email As String, Subj As String&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Dim Msg As String, URL As String&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Dim r As Integer, x As Double&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;For r = 3 To 5 &lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Email = Cells(r, 2)&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Subj = "Automated Mail Alert"&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Msg = ""&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Msg = Msg &amp;amp; "Hi " &amp;amp; Cells(r, 1) &amp;amp; "," &amp;amp; vbCrLf &amp;amp; vbCrLf&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Msg = Msg &amp;amp; "This is an automated mail alert generated using MS excel macros"&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Msg = Msg &amp;amp; Cells(r, 3).Text &amp;amp; "." &amp;amp; vbCrLf &amp;amp; vbCrLf&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Msg = Msg &amp;amp; UserName&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;URL = "mailto:" &amp;amp; Email &amp;amp; "?subject=" &amp;amp; Subj &amp;amp; "&amp;amp;body=" &amp;amp; Msg&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ShellExecute 0&amp;amp;, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Application.Wait (Now + TimeValue("0:00:04"))&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Application.SendKeys "%s"&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Next r&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;End Sub&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line by Line analysis of the Macro:&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Lines 1-4&lt;/b&gt; are required to define a shell command. Shell commands stand for those system commands which need not be part of excel, but are triggered using the macro.&lt;/div&gt;&lt;ol style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Private Declare Function ShellExecute Lib "shell32.dll" _&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;ByVal nShowCmd As Long) As Long&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 5 &lt;/b&gt;This is the start of our macro. This macro needs to be attached to a command button. The same macro can be attached to any event such as file open, file close, file save etc.&lt;/div&gt;&lt;ol start="5" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Private Sub CommandButton1_Click()&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 6-7 &lt;/b&gt;Just defined the username, this username will be used as a signature in the email. (there are ways to use shell commands and retrieve the user name from the windows user login, but I’ll cover that some other day)&lt;/div&gt;&lt;ol start="6" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Dim UserName As String&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;UserName = “Gulshan”&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 8&lt;/b&gt; Defined the email, subject, message body and mail link as strings&lt;/div&gt;&lt;ol start="8" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Dim Email As String, Subj As String&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Dim Msg As String, URL As String&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 10 &lt;/b&gt;Now comes the best part of this macro. You can send mails to more than one recipients using this macro and the message will go as an individual mail to each of them. We do this be maintaining a list in cells A3 – B5, column A contains the names and B contains the email addresses.&lt;/div&gt;&lt;ol start="10" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Dim r As Integer, x As Double&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 11 &lt;/b&gt;3&lt;sup&gt;rd&lt;/sup&gt; to 5&lt;sup&gt;th&lt;/sup&gt; rows in excel contain the email addresses. You can replace 5 with the last row of your list of mails.&lt;/div&gt;&lt;ol start="11" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;For r = 3 To 5 &lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 12 &lt;/b&gt;(r,2) tells the system to look at 2&lt;sup&gt;nd&lt;/sup&gt; column of each row and take the email address from there.&lt;/div&gt;&lt;ol start="12" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Email = Cells(r, 2)&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 13 &lt;/b&gt;Define the subject. (can also be set to pick up from a cell reference)&lt;/div&gt;&lt;ol start="13" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Subj = "Automated Mail Alert"&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 14 – 18 &lt;/b&gt;Create the message body: (vbCrLf sends “Enter” command or line break to the message)&lt;/div&gt;&lt;ol start="14" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Msg = ""&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Msg = Msg &amp;amp; "Hi " &amp;amp; Cells(r, 1) &amp;amp; "," &amp;amp; vbCrLf &amp;amp; vbCrLf&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Msg = Msg &amp;amp; "This is an automated mail alert generated using MS excel macros"&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ol start="17" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Msg = Msg &amp;amp; Cells(r, 3).Text &amp;amp; "." &amp;amp; vbCrLf &amp;amp; vbCrLf&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Msg = Msg &amp;amp; UserName&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt; text-indent: 24pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 19 – 20 &lt;/b&gt;Replace all the spaces in the message with the system code for space. This is done because the system will create a hyperlink and hyperlinks are not supposed to contain spaces.&lt;/div&gt;&lt;ol start="19" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 21 &lt;/b&gt;Replace all the line breaks in the message with the system code for line breaks. This is done because the system will create a hyperlink and hyperlinks are not supposed to contain line breaks.&lt;/div&gt;&lt;ol start="21" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 22 &lt;/b&gt;Create the URL link for the message by concatenating the above data.&lt;/div&gt;&lt;ol start="22" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;URL = "mailto:" &amp;amp; Email &amp;amp; "?subject=" &amp;amp; Subj &amp;amp; "&amp;amp;body=" &amp;amp; Msg&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 23 &lt;/b&gt;Execute the hyperlink. This is as good as clicking on the link. This will open a new outlook message window with the first recipient, subject and the message body.&lt;/div&gt;&lt;ol start="23" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;ShellExecute 0&amp;amp;, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 24 – 25 &lt;/b&gt;Now the system will wait for 4 seconds and then send the send command (keyboard strokes Alt+S) to send the mail. The 4 seconds wait has been created to accommodate for the system speed. You can change it depending on how fast or slow your system is.&lt;/div&gt;&lt;ol start="24" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Application.Wait (Now + TimeValue("0:00:04"))&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Application.SendKeys "%s"&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 26 &lt;/b&gt;Now move on to the next record.&lt;/div&gt;&lt;ol start="26" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;Next r&lt;/li&gt;&lt;/ol&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt 0.25in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;Line 27 &lt;/b&gt;End the macro after all mails have been sent.&lt;/div&gt;&lt;ol start="27" style="margin-top: 0in;" type="1"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in;"&gt;End Sub&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6329639272790607496-2655510320455446048?l=themacroguy.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://themacroguy.blogspot.com/feeds/2655510320455446048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://themacroguy.blogspot.com/2011/12/excel-macro-to-automatically-send.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6329639272790607496/posts/default/2655510320455446048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6329639272790607496/posts/default/2655510320455446048'/><link rel='alternate' type='text/html' href='http://themacroguy.blogspot.com/2011/12/excel-macro-to-automatically-send.html' title='Excel Macro to automatically send emails to a list of people'/><author><name>Gulshan Purswani</name><uri>http://www.blogger.com/profile/14154120268005119468</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
