+ Reply to Thread
Results 1 to 7 of 7

Adding an auto delete rows to yours already existing macro for emailing

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2012
    Location
    Batesville, MS
    MS-Off Ver
    Excel 2010
    Posts
    4

    Adding an auto delete rows to yours already existing macro for emailing

    Adding an auto delete rows to your already existing macro for emailing. Would like to delete Rows A and B after the
    worksheet is copied and emailed.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Adding an auto delete rows to yours already existing macro for emailing

    I guess you mean columns. Just add this line to the end of your macro -
    Worksheets("Sheet1").columns("A:B").delete
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    11-06-2012
    Location
    Batesville, MS
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Adding an auto delete rows to yours already existing macro for emailing

    Sub Mail_Every_Worksheet()
    'Working in 2000-2010
        Dim sh As Worksheet
        Dim wb As Workbook
        Dim FileExtStr As String
        Dim FileFormatNum As Long
        Dim TempFilePath As String
        Dim TempFileName As String
        Dim OutApp As Object
        Dim OutMail As Object
    
        TempFilePath = Environ$("temp") & "\"
    
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007-2010
            FileExtStr = ".xlsm": FileFormatNum = 52
        End If
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        Set OutApp = CreateObject("Outlook.Application")
    
        For Each sh In ThisWorkbook.Worksheets
            If sh.Range("B1").Value Like "?*@?*.?*" Then
    
                sh.Copy
                Set wb = ActiveWorkbook
    
                TempFileName = "Sheet " & sh.Name & " of " _
                             & ThisWorkbook.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
    
                Set OutMail = OutApp.CreateItem(0)
    
                With wb
                    .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
    
                    On Error Resume Next
                    With OutMail
                        .to = sh.Range("B1").Value
                        .CC = ""
                        .BCC = ""
                        .Subject = "3rd Shift Report"
                        .Body = ""
                        .Attachments.Add wb.FullName
                        'You can add other files also like this
                        '.Attachments.Add ("C:\test.txt")
                        .Display   'or use .Send
                    End With
                    On Error GoTo 0
    
                    .Close savechanges:=False
                End With
                Set OutMail = Nothing
    
                Kill TempFilePath & TempFileName & FileExtStr
    
            End If
        Next sh
    
        Set OutApp = Nothing
             
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
       
    End Sub
    This is my mail macro but the worksheet("ShiftReport".columns ("A:B").delete gives error...

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Adding an auto delete rows to yours already existing macro for emailing

    It should be
    worksheets("ShiftReport").columns ("A:B").delete

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Adding an auto delete rows to yours already existing macro for emailing

    msgtrainey,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.

  6. #6
    Registered User
    Join Date
    11-06-2012
    Location
    Batesville, MS
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Adding an auto delete rows to yours already existing macro for emailing

    My deepest apologies for not using the code tabs. Thank you for taking the time to help me. Thank you again

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Adding an auto delete rows to yours already existing macro for emailing

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1