Results 1 to 5 of 5

Thread: [RESOLVED] additional tab

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2019
    Posts
    128

    Resolved [RESOLVED] additional tab

    Hi

    I have the below code which copies a tab called Mainstay Master. Creates a xls then sends to a particular mail group with an attachment.

    Where do I add the code if I want to copy another tab called 'Mainstay Report' and include this in the same attachment as 'Mainstay Master. I.e my email attachment has two tabs included.

    The two tabs Mainstay master and Mainstay report are situated in the same file to copy.



    Dim w As Worksheet, b As Workbook, ol As Object, msg As Object
    Dim mypath As String, myfile As String, scc As String, sto As String
    mypath = "W:\.Team Documents\Freehold Team\Mainstay\Reporting\Reports"
    With Sheets("Control")
    sto = Join(WorksheetFunction.Transpose(Range("Mail_to")), ";")
    scc = Join(WorksheetFunction.Transpose(Range("Mail_cc")), ";")
    End With
    Set w = Sheets("Mainstay Master")
    Set b = Workbooks.Add
    w.Copy b.Sheets(1)
    myfile = mypath & Format(Date, "MMM") & " Mainstay Master.xlsx"
    Application.DisplayAlerts = False
    For sh = b.Sheets.Count To 2 Step -1
    b.Sheets(sh).Delete
    Next
    Application.DisplayAlerts = True
    b.SaveAs myfile
    Set ol = CreateObject("outlook.application")
    Set msg = ol.Createitem(0)
    With msg
    .To = sto
    .cc = scc
    .Subject = "Mainstay Report & Master file"
    .Body = "Good Morning"
    .attachments.Add myfile
    .display
    End With

    Workbooks("Freehold Manager Template V1").Sheets("Control").Activate
    Range("TimeStamp11").Value = Format(Now, "dd/mm/yy HH:mm:SS")

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: additional tab

    you can try like
    Code:
    Set w = Sheets("Mainstay Master")
    set x = sheets("Mainstay Report")
    Set b = Workbooks.Add
    w.Copy b.Sheets(1)
    x.copy b.sheets(,1)
    you would also need to change to
    Code:
    For sh = b.Sheets.Count To 3 Step -1
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2019
    Posts
    128

    Re: additional tab

    Breaks on this line....

    compile error

    Argument not optional.

    x.copy b.sheets(,1)

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: additional tab

    try
    Code:
    x.copy ,b.sheets(1)
    sorry comma in the wrong place
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2019
    Posts
    128

    Re: additional tab

    Perfect. Thank you.

Posting Permissions

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



Click Here to Expand Forum to Full Width