Consulting

Results 1 to 6 of 6

Thread: Email Selection

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Email Selection

    I use code to send out the Activeworkbook or the activeworksheet depending on what the user wants but now I am trying to set it up to send only what the user has selected. Preferably in the email if possible, if not as an attachment. here is the code I am trying:

    [VBA]
    Dim OL As Object
    Dim EmailItem As Object
    Dim FileName As String
    Dim y As Long
    Dim TempChar As String
    Dim SaveName As String

    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(0)
    FileName = ActiveSheet.Name & " - " & ActiveWorkbook.Name
    For y = 1 To Len(FileName)
    TempChar = Mid(FileName, y, 1)
    Select Case TempChar
    Case Is = "/", "\", "*", "?", """", "<", ">", "|", ":"
    Case Else
    SaveName = SaveName & TempChar
    End Select
    Next y
    Selection.Copy
    Set WB(1) = ActiveWorkbook
    WB(1).SaveAs SaveName
    WB(1).ChangeFileAccess xlReadOnly
    With EmailItem
    .Attachments.Add WB(1).FullName
    .Display
    End With
    Kill WB(1).FullName
    WB(1).Close False[/VBA]

  2. #2
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    and one other question for emailing purposes. All the code I use will crash if the program has never been saved before. So I tried this code:

    [VBA]
    If ThisWorkbook.Saved = False Then
    Error00_01_04.Show
    End If[/VBA]

    and Error00_01_04 shows up all the time. Even if the workbook has been saved before?

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Here's a link to John's stab at a similar task:
    http://vbaexpress.com/kb/getarticle.php?kb_id=880
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Thank you steve but I alread have the Active workbook and the Active Worksheet ones working (With help form the kb here and gurus like yourself) I am trying to make it even more useful by allowing the user to be able to select a few cells and then email just what the user selected and also I have the problem if the workbook has never been saved before?

  5. #5
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    Kind Regards,
    Ivan F Moala From the City of Sails

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Set 2 references....change the path in a couple of places...works great Ivan....thanks

    creates an html file which you can save or delete.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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