Consulting

Results 1 to 5 of 5

Thread: VB Code to Copy a table and place it in an email.

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    12
    Location

    VB Code to Copy a table and place it in an email.

    Hi All,

    Am working in Excel 07, but this would need to work in 2000 as well.

    Can anyone help with the following. Need a macro that will...
    1. Select a range of cells from B4 to RX. X is defined as the last row where Column A has a value.
    2. Copy the visible cells
    3. Open an email, enter "Submission" into the title, enter "Dear X," insert 2 returns.
    4.Paste the copied table into the body the email.

    Many Thanks
    JamesG

  2. #2
    VBAX Regular
    Joined
    Sep 2010
    Posts
    25
    Location
    Maybe this can help you get started. works for Outlook

    Create a command button under Control

    [VBA]Sub Send_Range()
    ' Select the range of cells on the active worksheet.
    ActiveSheet.Range("A1:Q30").Select

    ' Show the envelope on the ActiveWorkbook.
    ActiveWorkbook.EnvelopeVisible = True

    ' Set the optional introduction field thats adds
    ' some header text to the email body. It also sets
    ' the To and Subject lines. Finally the message
    ' is sent.
    With ActiveSheet.MailEnvelope
    .Introduction = "Subject Title"
    .Item.To = "E-Mail_Address_Here"
    .Item.Subject = "Email Description"
    .Item.Send
    End With
    End Sub[/VBA]

    where: .Range("Range of cell you want to see in your email").

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Regular
    Joined
    Aug 2009
    Posts
    12
    Location

    Selecting a variable range for Copying

    Hi,

    Working with Excel 2007 in Vista

    It is points 1 and 2 that need the most help with.

    1. Select a range of cells from B4 to RX. X is defined as the last row where Column A has a value.
    2. Copy the visible cells

    Thanks

  5. #5
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    To find the last data filled row (X in your case) would be:
    [VBA]Dim X as long
    X = Range("A" & Rows.count).End(xlUp).Row
    Range("B4:R" & X).Select[/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

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