Consulting

Results 1 to 2 of 2

Thread: VB Code partially working

  1. #1
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    1
    Location

    VB Code partially working

    Hello,

    I am trying to capture the edits only from a workbook and then email them as a single sheet attachment but the code I have just emails the whole workbook so I don't know what has been changed!

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Not Application.Intersect(Range("A1:O200"), Target) Is Nothing Then
    
    If Target.Value = "0" Then
    'if cell in "M" = 0 run the macro
    str = Cells(Target.Row, "M").Value
    
    Sub Mail_Workbook_1()
        Dim OutApp As Object
        Dim OutMail As Object
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = "steven@bellsdomestics.co.uk"
            .CC = ""
            .BCC = ""
            .Subject = "The stock has been updated"
            .Body = "Bells Stock Updated"
            .Attachments.Add ActiveWorkbook.FullName
            .Send
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    This will attach the entire bokk for which ever book you are in when you run the macro

    [VBA]Sub Mail_Workbook_1()
    .
    .
    .
    .Attachments.Add ActiveWorkbook.FullName[/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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