Consulting

Results 1 to 4 of 4

Thread: Macro to copy paste data

  1. #1
    VBAX Newbie
    Joined
    Aug 2009
    Posts
    1
    Location

    Macro to copy paste data

    Hi
    below mention code copy paste & send entire row to outlok email body,but if there is one email id in B column and 4 row are belogns to that email id what will be code, it mean it copy row till find another email id in find in B column.

    [VBA]Option Explicit
    Sub Send_Row()
    ' Don't forget to copy the function RangetoHTML in the module.
    ' Working in Office 2000-2007
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim rng As Range
    Dim Ash As Worksheet
    Dim StrBody As String
    Dim StrhBody As String

    StrBody = "Dear Sir/Madam," & "
    " & _
    "Line 1" & "
    " & _
    "Line 2" & "
    " & _
    "Line 3" & "


    "

    StrhBody = "Line A" & "
    " & _
    "Line B" & "
    " & _
    "Line C" & "

    "
    Set Ash = ActiveSheet
    On Error GoTo cleanup
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon

    With Application
    .EnableEvents = False
    .ScreenUpdating = False
    End With

    For Each cell In Ash.Columns("B").Cells.SpecialCells(xlCellTypeConstants)

    If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 1).Value) = "yes" Then

    Ash.Range("A1:O100").AutoFilter Field:=2, Criteria1:=cell.Value
    With Ash.AutoFilter.Range
    On Error Resume Next
    Set rng = .SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    End With

    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
    .To = cell.Value

    .Subject = "Test Mail"
    .HTMLBody = StrBody & RangetoHTML(rng) & "
    " & StrhBody
    .Display 'Or use Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Ash.AutoFilterMode = False
    End If
    Next cell
    cleanup:
    Set OutApp = Nothing
    With Application
    .EnableEvents = True
    .ScreenUpdating = True
    End With
    End Sub
    ' -----------------------------------------------------------------------
    'NameEmail 'IDYes/NoLocationIDNoCVAmountAabc@gmail.comyesABC154114112612345636108Bcbc@gmail.comyesABC154114112612345636108Cbcc@gmail.comyesABC154114231556461000ABC15411411261234565000ABC15411411261234564000ABC154114112612345612500
    [/VBA]

  2. #2
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Your question appears to be something like "how to copy Excel data into an Outlook mail item". You have posted the question to the MSProject forum. Far more people use VBA with Outlook and/or Excel than with MSProject. So you will likely get better results if you post this question in either the Excel or the Outlook forum.
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Moved to Excel help forum.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a sample workbook on which we can test your code. Use Manage Attachments in the Go Advanced reply section.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •