HELP required - VBA code modification.

geethanjali63

New Member
Joined
Dec 7, 2015
Messages
49
Dear All MVP's,I am basic user, not much knowledge in macro. currently I am using Ron de bruin's mail send with excel row and rows.i need small change in this code,I tried but not able to complete.I will explain my 2 requirement is given in last, if required I shared the code below after my requirement points..

My file data is 300,000+ row. Important condition is per user account, 1 reminder mail only, even multiple pending data also.

1. This macro is copying complete "A" column data from the same file and inserting one new sheets and pasting.
2. then removing duplicates to reach unique. Now as per this unique value (account number) used for filtering.
3. Now back to sheet 1, and applying filter in column "A". getting complete pending data of one account number. That filtered data's (visible cells only) pasted in new workbook(temporary), then again that data copied and pasted in outlook body of the message below my greeting message in outlook mail with that account's mail id. then that temporary file deleted.

My Requirement is
A. Currently my mails going with same person name like Dear XYZ, because it is taking from my main sheet "A" column 2nd cell . I need this temporary data's "A" column second cell (account holder name) data to be my email addressing person name (Dear XYZ)

B. Outlook signature should used after the pasted data.

Module 1

Sub Send_Row_Or_Rows_1()
Dim OutApp As Object
Dim OutMail As Object
Dim rng As Range
Dim Ash As Worksheet
Dim Cws As Worksheet
Dim Rcount As Long
Dim Rnum As Long
Dim FilterRange As Range
Dim FieldNum As Integer
Dim StrBody As String
Dim myName As String

myName = Range("C2").Value

StrBody = "Dear " & myName & "," & _
"Please find the pending video information," & _ "Kindly go through the videos ASAP.
" & _ "Ron's Excel Page
" & _ "

Thank you"On Error GoTo cleanupSet OutApp = CreateObject("Outlook.Application")With Application.EnableEvents = False.ScreenUpdating = FalseEnd With'Set filter sheet, you can also use Sheets("MySheet")Set Ash = ActiveSheet'Set filter range and filter column (Column with names)Set FilterRange = Ash.Range("A1:H" & Ash.Rows.Count)FieldNum = 1 'Filter column = A because the filter range start in A'Add a worksheet for the unique list and copy the unique list in A1Set Cws = Worksheets.AddFilterRange.Columns(FieldNum).AdvancedFilter _Action:=xlFilterCopy, _CopyToRange:=Cws.Range("A1"), _CriteriaRange:="", Unique:=True'Count of the unique values + the header cellRcount = Application.WorksheetFunction.CountA(Cws.Columns(1))'If there are unique values start the loopIf Rcount >= 2 ThenFor Rnum = 2 To Rcount'Filter the FilterRange on the FieldNum columnFilterRange.AutoFilter Field:=FieldNum, _Criteria1:=Cws.Cells(Rnum, 1).Value'Look for the mail address in the MailInfo worksheetmailAddress = ""On Error Resume NextmailAddress = Application.WorksheetFunction. _VLookup(Cws.Cells(Rnum, 1).Value, _Worksheets("Sheet1").Range("A1:B" & _Worksheets("Sheet1").Rows.Count), 2, False)On Error GoTo 0If mailAddress <> "" ThenWith Ash.AutoFilter.RangeOn Error Resume NextSet rng = .SpecialCells(xlCellTypeVisible)On Error GoTo 0End WithSet OutMail = OutApp.CreateItem(0)On Error Resume NextWith OutMail.To = mailAddress.Subject = "Test mail".HTMLBody = RangetoHTML(rng).HTMLBody = StrBody & .HTMLBody.Send'Or use SendEnd WithOn Error GoTo 0Set OutMail = NothingEnd If'Close AutoFilterAsh.AutoFilterMode = FalseNext RnumEnd Ifcleanup:Set OutApp = NothingApplication.DisplayAlerts = FalseCws.DeleteApplication.DisplayAlerts = TrueWith Application.EnableEvents = True.ScreenUpdating = TrueEnd WithEnd Sub


Module 2

Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006' Working in Office 2000-2016

Dim fso As Object Dim ts As Object Dim TempFile As String Dim TempWB As Workbook TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm" 'Copy the range and create a new workbook to past the data in rng.Copy Set TempWB = Workbooks.Add(1) With TempWB.Sheets(1) .Cells(1).PasteSpecial Paste:=8 .Cells(1).PasteSpecial xlPasteValues, , False, False .Cells(1).PasteSpecial xlPasteFormats, , False, False .Cells(1).Select Application.CutCopyMode = False On Error Resume Next .DrawingObjects.Visible = True .DrawingObjects.Delete On Error GoTo 0 End With 'Publish the sheet to a htm file With TempWB.PublishObjects.Add( _ SourceType:=xlSourceRange, _ Filename:=TempFile, _ Sheet:=TempWB.Sheets(1).Name, _ Source:=TempWB.Sheets(1).UsedRange.Address, _ HtmlType:=xlHtmlStatic) .Publish (True) End With 'Read all data from the htm file into RangetoHTML Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2) RangetoHTML = ts.ReadAll ts.Close RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _ "align=left x:publishsource=") 'Close TempWB TempWB.Close savechanges:=False 'Delete the htm file we used in this function Kill TempFile Set ts = Nothing Set fso = Nothing Set TempWB = NothingEnd Function
 
Last edited:
moi, I was referring to post #1 and not #9 :)
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
moi, I was referring to post #1 and not #9 :)
In that case it would be a different "as noted previously".
Dear S.H.D.O.,
Thanks for your advise. Actually I am pasting properly, but after posting it's getting converted like that. I don't know how to correct it.
Are you enclosing your VBA with CODE tags? Please see how-to guide here:
http://www.mrexcel.com/forum/board-...post-your-visual-basic-applications-code.html

Caleeco
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,533
Messages
6,160,382
Members
451,644
Latest member
mkotas

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top