Results 1 to 4 of 4

Thread: Copying Of Rows and Header In new workbook and E-mail

  1. #1
    Join Date
    Aug 2009
    Posts
    51

    Copying Of Rows and Header In new workbook and E-mail

    I have been using the rows and columns and also I wanted to get the excel in Macro and it is that will they copy rows and the pasting of the files that can be done into the new workbook and then attaching the workbook to the files of the Outlook E-mail to send the files through it. I wanted to get the details of the messages that will be added to the message of the body in the E-mail and the various E-mail addresses in it. Please tell me that how it can be done and the proper solution for it.

  2. #2
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Copying Of Rows and Header In new workbook and E-mail

    You can try the code that is given below for the attaching of the various files and also the header details and workbook information by just using the code that is given below:
    Code:
    ub Sort_By_Make()
    
    On Error Resume Next
    
     Dim objOutlook As Object
     Dim Mail As Object
    
    vName = ActiveWorkbook.Name
    vSheet = ActiveSheet.Name
    
    Columns("A:E").Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    
    For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    
    vStart = i
    
    Do Until Workbooks(vName).Sheets(vSheet).Range("D" & i).Value <> Range("D" & i + 1).Value
    i = i + 1
    Loop
    
    Workbooks.Add
    vNewBook = ActiveWorkbook.Name
    
    Workbooks(vName).Sheets(vSheet).Range("A1:E1").Copy Destination:=Workbooks(vNewBook).Sheets("Sheet1").Range("A1")
    
    Workbooks(vName).Sheets(vSheet).Range("A" & vStart & ":E" & i).Copy Destination:=Workbooks(vNewBook).Sheets("Sheet1").Range("A2")
    
    Cells.AutoFilter
    Columns.EntireColumn.AutoFit
    vPath = "C:\Test\" & Replace(Date, "/", "_") & " " & Workbooks(vName).Sheets(vSheet).Range("D" & i).Value & " 3rd Follow-up " & Replace(Time, ":", "_") & ".xlsm"
    ActiveWorkbook.SaveAs (vPath)
    vNewName = ActiveWorkbook.Name
    Workbooks(vNewName).Close
    
    
        Set objOutlook = CreateObject("Outlook.Application")
        Set objMail = objOutlook.CreateItem(0)
        With objMail
            .Subject = Replace(vNewName, ".xlsm", "")
                 
                 For j = 3 To Sheets("Email Addresses").Cells((Application.WorksheetFunction.Match((Workbooks(vName).Sheets(vSheet).Range("D" & i).Value), Sheets("Email Addresses").Range("A:A"), 0)), Columns.Count).End(xlToLeft).Column
          
          If Err.Number = 1004 Then
          For Each vTab In Sheets
          If vTab.Name = "Errors" Then
          vFound = True
          End If
          Next vTab
          
          If vFound <> True Then
          Sheets.Add.Name = "Errors"
          Sheets("Errors").Range("A1").Value = "NOT FOUND"
          End If
          Sheets("Errors").Range("A" & Sheets("Errors").Range("A" & Rows.Count).End(xlUp).Row + 1).Value = Workbooks(vName).Sheets(vSheet).Range("D" & i).Value
          Err.Clear
          GoTo Skip
          End If
          
           vNames = Workbooks(vName).Sheets("Email Addresses").Cells(Application.WorksheetFunction.Match(Workbooks(vName).Sheets(vSheet).Range("D" & i).Value, Workbooks(vName).Sheets("Email Addresses").Range("A:A"), 0), j).Value
          .Recipients.Add (vNames)
                 Next j
            .attachments.Add vPath
            .Body = Workbooks(vName).Sheets("Email Addresses").Range("B" & Application.WorksheetFunction.Match(Workbooks(vName).Sheets(vSheet).Range("D" & i).Value, Workbooks(vName).Sheets("Email Addresses").Range("A:A"), 0)).Value
        End With
        
        objMail.display
        'objMail.Send
        
    Skip:
    
        Set objMail = Nothing
        Set objOutlook = Nothing
    
    Next i
    
    End Sub
    And see that whether it is working out for you or not.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Copying Of Rows and Header In new workbook and E-mail

    The other option that you can just use is sort the files that are being used for the Macro and then see out the various details of the files that you are using for the setting of the columns. And also you can make the references of the files that will be used for the spreadsheets and the settings of the various data’s with the E-mail data. And also you can just check out the rows that are present in the spreadsheet and then you can make the use of the macros.

  4. #4
    Join Date
    Nov 2008
    Posts
    1,022

    Re: Copying Of Rows and Header In new workbook and E-mail

    And also it is that you can just sort out the files that are used for the rows that you just want to mail it through the outlook and then you have to save the file in the new format of the spreadsheet. There in which you are applying the details of the Macros should be used by selecting the files that you will be sending out through the E-mail and then make the use of the Outlook for the sending of the details of the files. And also you can just separate the details of the price and then just see that whether the files that you wanted are being sent by making the use of the above solutions.

Similar Threads

  1. Connect USB 3.0 front case panel header to motherboard w/o a header?
    By Dogs-Day-Out in forum Motherboard Processor & RAM
    Replies: 4
    Last Post: 14-04-2012, 07:02 PM
  2. Replies: 3
    Last Post: 11-07-2011, 10:37 AM
  3. Mail Prints Header only in Tiger Mail
    By Juany in forum Windows Software
    Replies: 4
    Last Post: 17-03-2010, 09:44 PM
  4. Replies: 2
    Last Post: 09-07-2009, 08:57 AM
  5. How to delete hidden rows in Workbook using Macros ?
    By Dwij in forum Windows Software
    Replies: 4
    Last Post: 21-04-2009, 02:16 PM

Tags for this Thread

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
  •  
Page generated in 1,714,012,330.91706 seconds with 16 queries