+ Reply to Thread
Results 1 to 17 of 17

VBA to Create new workbook with 2 worksheet and save 10 times then send all via outlook

Hybrid View

  1. #1
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    VBA to Create new workbook with 2 worksheet and save 10 times then send all via outlook

    Help PLEASE - I have a workbook with 30 odd worksheets, I am trying to get 2 worksheets to copy and save into new workbook 10 times and then attach the new workbooks to email (Outlook ) to send.

    For Example: the below code does what i want for the 2 worksheets with the correct name of the file but won't work through the rest...

    strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName = "Binalong 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Binalong Details", "Binalong Player_Records")).Select
        Sheets("Binalong Player_Records").Activate
        Sheets(Array("Binalong Details", "Binalong Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    Last edited by alansidman; 09-24-2018 at 01:05 AM.

  2. #2
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Copy of sheet attached
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Please Help - I'm self taught in VBA so don't know the in and outs.
    Even if I could get the 2 worksheets to a new workbook and then email, I would create a button on each sheet to do this, just means I would have to send 10 different emails.
    I have spent the best part of the last 3 days trying different things and running them through marcos and trying to debug, just can't get it right...

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,944

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Alan - Tried to do this but I kept getting error message saying - I was unable to post links or images until I had most post ??
    Thanks - I'm new to all this but I will try to comply best I can.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,300

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Morning Chris76

    Seems to me all you need to do is make one copy only and mail to 10 different users...is this correct...herewith an example of how it could work...saving the email addresses and recipient names in a sheet...

    Option Explicit
    
    Sub Copy_Send()
    Dim strPath As String, StrFName As String, File As String, i As Long
    Application.ScreenUpdating = False
    strPath = ThisWorkbook.Path
    StrFName = "Binalong 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
    File = strPath & "\" & StrFName & ".xlsm"
    Sheets(Array("Binalong Details", "Binalong Player_Records")).Copy
    ActiveWorkbook.SaveAs File, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    ActiveWorkbook.Close
    For i = 1 To 10
        With CreateObject("Outlook.Application").Createitem(0)
                .Display
                .To = ActiveSheet.Range("B" & i + 1)
                .Subject = "Whatever yo want to say in the Email Subject"
                .HTMLBody = "Hallo " & ActiveSheet.Range("A" & i + 1) & "<br><br>" & "Whatever you want to say in the Email Body" & .HTMLBody
                .Attachments.Add File
                '.Send 'Uncomment once you want to run your code....
        End With
    Next i
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by sintek; 09-24-2018 at 02:35 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  7. #7
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Sintek -Thanks for the reply...here is code I have, I just can't debug it, must be doing something wrong, yours would work for 1 but I have 10 to extract the same way and emails go to the same people each time..

    Sub Send_Player_Participation_Email()
    '
    ' Send_Player_Participation_Email Macro
    ' Create PDF of active sheet and send as attachment.
    '
        Dim strPath As String, strFName As String, strFName1 As String, strFName2 As String, strFName3 As String, strFName4 As String, _
        strFName6 As String, strFName7 As String, strFName8 As String, strFName9
        Dim OutApp As Object, OutMail As Object
        
         'Create New Workbook for Each File
         
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName = "Binalong 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Binalong Details", "Binalong Player_Records")).Select
        Sheets("Binalong Player_Records").Activate
        Sheets(Array("Binalong Details", "Binalong Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName1 = "Boorowa Rec 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Bwa Rec Details", "Bwa Rec Player_Records")).Select
        Sheets("Bwa Rec Player_Records").Activate
        Sheets(Array("Bwa Rec Details", "Bwa Rec Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName1 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName2 = "Boorowa Ex 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Bwa Ex Details", "Bwa Ex Player_Records")).Select
        Sheets("Bwa Ex Player_Records").Activate
        Sheets(Array("Bwa Ex Details", "Bwa Ex Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName2 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName3 = "Bribbaree 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Bribbaree Details", "Bribbaree Player_Records")).Select
        Sheets("Bribbaree Player_Records").Activate
        Sheets(Array("Bribbaree Details", "Bribbaree Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName3 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName4 = "Cootamundra 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Coota CC Details", "Coota CC Player_Records")).Select
        Sheets("Coota CC Player_Records").Activate
        Sheets(Array("Coota CC Details", "Coota CC Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName4 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName5 = "Cootamundra Ex 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Coota Ex Details", "Coota Ex Player_Records")).Select
        Sheets("Coota Ex Player_Records").Activate
        Sheets(Array("Coota Ex Details", "Coota Ex Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName5 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName6 = "Harden 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Harden Details", "Harden Player_Records")).Select
        Sheets("Harden Player_Records").Activate
        Sheets(Array("Harden Details", "Harden Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName6 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName7 = "Quandialla 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Quandi Details", "Quandi Player_Records")).Select
        Sheets("Quandi Player_Records").Activate
        Sheets(Array("Quandi Details", "Quandi Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName7 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName8 = "Stockinbingal 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Stock Details", "Stock Player_Records")).Select
        Sheets("Stock Player_Records").Activate
        Sheets(Array("Stock Details", "Stock Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName8 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
        strPath = "C:\Users\cgrimson\Essential Energy\Boorowa Depot - Documents\SharePoint Docs\Bowls\Pennants 2019\Testing folder\" 'Or any other path, but include trailing "\"
        strFName9 = "Young 2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
       
        Sheets(Array("Yng Details", "Yng Player_Records")).Select
        Sheets("Yng Player_Records").Activate
        Sheets(Array("Yng Details", "Yng Player_Records")).Copy
        ActiveSheet.SaveAs FileName:=strPath & strFName9 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    
         'Set up outlook
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
         'Create message
        On Error Resume Next
        With OutMail
            .To = "[email protected]" 'Insert required address here ########
            .CC = "[email protected]"
            .BCC = "[email protected]"
            .Subject = "SWDBA Pennant Results 2019"
            .Body = "  Hi All" & vbCr & vbCr _
            & "  The attached PDF is the updated Pennant Results, Please check the results to see if they are correct" & vbCr & vbCr _
            & "  Also in the attached PDF is a Skip's Ranking, for Interest" & vbCr & vbCr _
            & "  If there are any discrepancies, please let me know" & vbCr & vbCr _
            & "  Regards" & vbCr & vbCr _
            & "  Chris Grimson" & vbCr
            .Attachments.Add strPath & strFName
            .Display   'Use only during debugging ##############################
            .Send      'Uncomment to send e-mail ##############################
        End With
         'Delete any temp files created
       
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
    
    End Sub

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,300

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    So...You are wanting to copy 2 x different worksheets each time to a new workbook...10 times
    Option Explicit
    
    Sub Copy_Send()
    Dim strFileArr, shtArr, strPath As String, strFName As String, File As String, i As Long
    Application.ScreenUpdating = False
    strPath = ThisWorkbook.Path
    strFileArr = Array("Binalong ", "Boorowa Rec ", "Boorowa Ex ", "Bribbaree ", "Cootamundra ", "Cootamundra Ex ", "Harden ", "Quandialla ", "Stockinbingal ", "Young ")
    strFName = "2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
    shtArr = Array("Binalong Details", "Binalong Player_Records", "Bwa Rec Details", "Bwa Rec Player_Records", "Bwa Ex Details", _
        "Bwa Ex Player_Records", "Bribbaree Details", "Bribbaree Player_Records", "Coota CC Details", "Coota CC Player_Records", _
        "Coota Ex Details", "Coota Ex Player_Records", "Harden Details", "Harden Player_Records", "Quandi Details", _
        "Quandi Player_Records", "Stock Details", "Stock Player_Records", "Yng Details", "Yng Player_Records")
    For i = 1 To 10
        Sheets(Array(shtArr(i - 1), shtArr(i))).Copy
        File = strPath & "\" & strFileArr(i - 1) & strFName & ".xlsm"
        ActiveWorkbook.SaveAs File, FileFormat:=xlOpenXMLWorkbookMacroEnabled
        ActiveWorkbook.Close
        With CreateObject("Outlook.Application").CreateItem(0)
                .Display
                .To = ActiveSheet.Range("B" & i + 1)
                .Subject = "SWDBA Pennant Results 2019"
                .HTMLBody = "  Hi All" & "<br><br>" _
                            & "  The attached FILE is the updated Pennant Results, Please check the results to see if they are correct" & "<br><br>" _
                            & "  Also in the attached FILE is a Skip's Ranking, for Interest" & "<br><br>" _
                            & "  If there are any discrepancies, please let me know" & "<br><br>" _
                            & "  Regards" & "<br><br>" _
                            & "  Chris Grimson" & vbCr & .HTMLBody
                .Attachments.Add File
                '.Send 'Uncomment once you want to run your code....
        End With
    Next i
    Application.ScreenUpdating = True
    End Sub
    And send to 10 different recipients...
    Where are the email cc, bcc addresses of the recipients stored...
    The attached PDF
    but yet you are saving as a macro-enabled workbook not pdf
    Last edited by sintek; 09-25-2018 at 02:27 AM.

  9. #9
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    I had this code for PDF but they, the " governing body " wants the original macro-enabled workbooks and I just couldn't work out the change,...

    With your code when I go back into the file location the files are their created as expected with the correct file names, just getting the download error on the emails, worst case I will just modify your to code just do the files and do the emails manually now that I have files extracted and saved quickly but would rather that the VBA works and do it with one hit of the button and i'm done

    Thanks for your help...

  10. #10
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Sintek - Just a quick question, Is there anyway to modify the code so that it opens just 1 email with the 10 attachments in it, instead of 10 emails with 1 attachment in each email ??
    This would be a perfect fit for me if we can do this ...

    Cheers and Thanks again for everyone's help...

  11. #11
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Sintek - Yes - Your code works great but I get a download error on the attachment in the email when it opens up, I get the 10 Emails with the correct attachments which is great but get this download error... The emails will go to the same people each time, but that is an easy fix with your code. Just don't why I am getting a download error ??
    The files are saving to a share point file in office ?? do you know of any problems with doing this ??? Maybe if I changed it to a "C:/" Drive location I wouldn't get the download error..

    Any thoughts ??Download Error View.docx

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,300

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Is your code is within the workbook that contains all the sheets...
    And this workbook is saved in your particular path...
    Is there anyway to modify the code so that it opens just 1 email with the 10 attachments in it, instead of 10 emails with 1 attachment in each email ?
    Yes, this can easily be achieved...Something like this...Untested...Pls upload a sample file which contains all the sheets so that we can make use of for testing...
    Option Explicit
    
    Sub Copy_Send()
    Dim strFileArr, shtArr, strPath As String, strFName As String, File(1 To 10) As String, i As Long
    Application.ScreenUpdating = False
    strPath = ThisWorkbook.Path
    strFileArr = Array("Binalong ", "Boorowa Rec ", "Boorowa Ex ", "Bribbaree ", "Cootamundra ", "Cootamundra Ex ", "Harden ", "Quandialla ", "Stockinbingal ", "Young ")
    strFName = "2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
    shtArr = Array("Binalong Details", "Binalong Player_Records", "Bwa Rec Details", "Bwa Rec Player_Records", "Bwa Ex Details", _
        "Bwa Ex Player_Records", "Bribbaree Details", "Bribbaree Player_Records", "Coota CC Details", "Coota CC Player_Records", _
        "Coota Ex Details", "Coota Ex Player_Records", "Harden Details", "Harden Player_Records", "Quandi Details", _
        "Quandi Player_Records", "Stock Details", "Stock Player_Records", "Yng Details", "Yng Player_Records")
    For i = 1 To 10
        Sheets(Array(shtArr(i - 1), shtArr(i))).Copy
        File(i) = strPath & "\" & strFileArr(i - 1) & strFName & ".xlsm"
        ActiveWorkbook.SaveAs File(i), FileFormat:=xlOpenXMLWorkbookMacroEnabled
        ActiveWorkbook.Close
    Next i
    With CreateObject("Outlook.Application").CreateItem(0)
            .Display
            .To = ActiveSheet.Range("B" & i + 1)
            .Subject = "SWDBA Pennant Results 2019"
            .HTMLBody = "  Hi All" & "<br><br>" _
                    & "  The attached FILE is the updated Pennant Results, Please check the results to see if they are correct" & "<br><br>" _
                    & "  Also in the attached FILE is a Skip's Ranking, for Interest" & "<br><br>" _
                    & "  If there are any discrepancies, please let me know" & "<br><br>" _
                    & "  Regards" & "<br><br>" _
                    & "  Chris Grimson" & vbCr & .HTMLBody
        For i = 1 To 10
            .Attachments.Add File(i)
        Next i
        '.Send 'Uncomment once you want to run your code....
    End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by sintek; 09-25-2018 at 08:43 AM.

  13. #13
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    SINTEK - Awesome Stuff your code work a charm, Thanks for the help

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,300

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Pleasure...
    If you feel I have helped, please click on the star to left of post [Add Reputation]

  15. #15
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    SINTEK HELP - When I run the code everything works fine EXCEPT for the attached sheets to the correct File.

    The below is a list of the excel files generated by the code, which is CORRECT for the File Names but the sheets in each File doesn't correspond to the correct Files Name, except for the first one in the code "Binalong"

    Binalong 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - THE ONLY FILE THAT IS CORRECT - ATTACHED SHEETS ARE -
    "Binalong Details", "Binalong Player_Records"

    Boorowa Rec 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Bwa Rec Details", "Binalong Player_Records"

    Boorowa Ex 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Bwa Rec Details", "Bwa Rec Player_Records"

    Bribbaree 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Bwa Ex Details", "Bwa Rec Player_Records"

    Cootamundra 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Bwa Ex Details", "Bwa Ex Player_Records"

    Cootamundra Ex 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Bribbaree Details", "Bwa Ex Player_Records"

    Harden 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Bribbaree Details", "Bribbaree Player_Records"

    Quandialla 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Coota CC Details",, "Bribbaree Player_Records"

    Stockinbingal 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Coota CC Details", "Coota CC Details"

    Young 2019 SWDBA Pennants Player Participation Record 18-Oct-18.xlsm - INCORRECT - ATTACHED SHEETS ARE -
    "Coota Ex Details", "Coota CC Details"


    I have tried to change the code around to get it work without luck, any help or ideas would be great....

    Code and File Attached for you




    Sub Player_Particpation_Record()
    Dim strFileArr, shtArr, strPath As String, strFName As String, File(1 To 10) As String, i As Long
    Application.ScreenUpdating = False
    strPath = ThisWorkbook.Path
    strFileArr = Array("Binalong ", "Boorowa Rec ", "Boorowa Ex ", "Bribbaree ", "Cootamundra ", "Cootamundra Ex ", "Harden ", "Quandialla ", "Stockinbingal ", "Young ")
    strFName = "2019 SWDBA Pennants Player Participation Record " & Format(Date, "DD-MMM-YY")
    shtArr = Array("Binalong Details", "Binalong Player_Records", "Bwa Rec Details", "Bwa Rec Player_Records", "Bwa Ex Details", _
        "Bwa Ex Player_Records", "Bribbaree Details", "Bribbaree Player_Records", "Coota CC Details", "Coota CC Player_Records", _
        "Coota Ex Details", "Coota Ex Player_Records", "Harden Details", "Harden Player_Records", "Quandi Details", _
        "Quandi Player_Records", "Stock Details", "Stock Player_Records", "Yng Details", "Yng Player_Records")
    For i = 1 To 10
        Sheets(Array(shtArr(i - 1), shtArr(i))).Copy
        File(i) = strPath & "\" & strFileArr(i - 1) & strFName & ".xlsm"
        ActiveWorkbook.SaveAs File(i), FileFormat:=xlOpenXMLWorkbookMacroEnabled
        ActiveWorkbook.Close
    Next i
    With CreateObject("Outlook.Application").CreateItem(0)
            .Display
            .To = "[email protected]" 'Insert required address here ########
            .CC = "[email protected]"
            .BCC = "[email protected]"
            .Subject = "SWDBA Pennant Player Particpation Records 2019"
            .HTMLBody = "  Hi All" & "<br><br>" _
                    & "  The attached FILE is the updated Pennant Player Particpation Records 2019" & "<br><br>" _
                    & "  This is for all Clubs in SWDBA" & "<br><br>" _
                    & "  If there are any discrepancies, please let me know" & "<br><br>" _
                    & "  Regards" & "<br><br>" _
                    & "  Chris Grimson" & vbCr & .HTMLBody
        For i = 1 To 10
            .Attachments.Add File(i)
        Next i
        '.Send 'Uncomment once you want to run your code....
    End With
    Application.ScreenUpdating = True
    End Sub

  16. #16
    Registered User
    Join Date
    09-17-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    Can anyone help me correct the code above !!!

  17. #17
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,300

    Re: VBA to Create new workbook with 2 worksheet and save 10 times then send all via outloo

    As per previous requests...pls upload a sample file with the correct sheets that can be used for testing...
    Also...What is your expected outcome...
    Last edited by sintek; 10-19-2018 at 12:39 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Create Macro to copy worksheet into new workbook, change things& drop into Outlook
    By sspatriots in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-19-2017, 09:17 AM
  2. [SOLVED] Create, rename, and save new worksheet and workbook
    By peihsin.lee in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2017, 05:04 AM
  3. [SOLVED] Events running multiple times per worksheet on workbook save
    By JimBobW in forum Excel General
    Replies: 4
    Last Post: 01-21-2016, 09:04 AM
  4. [SOLVED] need to save one worksheet into pdf and send via outlook
    By AWITCHER in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2015, 09:41 AM
  5. [SOLVED] Create New Message in Outlook, Don't Send
    By athyeh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-20-2014, 10:33 AM
  6. [SOLVED] Create button to Save specific page ranges from each worksheet in the workbook
    By projectatpel in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-16-2014, 02:22 PM
  7. Save range and send as outlook email
    By hejbeiter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2012, 12:50 PM

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