emailing worksheets without formulas

gtrplayer5150

New Member
Joined
Nov 21, 2005
Messages
16
I'm using the following code to copy 2 sheets of a workbook and email them. Everything works fine but the file that it emails is 3M and it tries to run the code in thisworkbook. I just want to send a snapshot of the two sheets so the recipient can print them out. I've tried using the PastSpecial function but can't get it to work. Any ideas?

thanks


Code:
Private Sub cmdSend_Click()

Dim wb As Workbook
    Dim strdate As String
    strdate = Format(Now, "mm-dd-yy")
    Application.ScreenUpdating = False
    Sheets(Array("8d supplier cover sheet", "#5035e")).Copy
    Set wb = ActiveWorkbook
    With wb
        .SaveAs "Scar Report - " & Sheets("8d supplier cover sheet").Range("b5").Value _
                    & ".xls"
              
        .SendMail Sheets("8d supplier cover sheet").Range("j1").Value, _
                     "Scar Number: " & Sheets("8d supplier cover sheet").Range("b5").Value
                     
        .ChangeFileAccess xlReadOnly
        Kill .FullName
        .Close False
    End With
    Application.ScreenUpdating = True
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
What have you tried exactly? Btw, any mass-PasteSpecial method will fail if cell A1 is merged, so I hope this is not the case.
 
Upvote 0
I've put this code after the .copy command. But I do have cell A1 merged so that would explain a lot of things.

Code:
Worksheets.Select
Cells.Copy
Cells.PasteSpecial xlPasteValues
Cells(1).Select
Worksheets(1).Select
Application.CutCopyMode = False
 
Upvote 0
Yes, it will fail (as you've seen). Unmerge A1 and it will work just fine.
 
Upvote 0
Ok, so I unmerge cell A1 and I run this code and it emails the worksheets but when I open the file it tries to run the code in thisworkbook. I then go back to my original file and all of the formulas are wiped out. Luckily I have a backup. Any ideas?

thanks

Code:
    Dim wb As Workbook
    Dim strdate As String
    strdate = Format(Now, "mm-dd-yy")
    Application.ScreenUpdating = False
    Sheets(Array("8d supplier cover sheet", "#5035e")).Copy
    Worksheets.Select
    Cells.Copy
    Cells.PasteSpecial xlPasteValues
    Sheets(1).Select
    Worksheets(1).Select
    Application.CutCopyMode = False

    Set wb = ActiveWorkbook
    With wb
        .SaveAs "Scar Report - " & Sheets("8d supplier cover sheet").Range("b5").Value _
                    & ".xls"
              
        .SendMail Sheets("8d supplier cover sheet").Range("j1").Value, _
                     "Scar Number: " & Sheets("8d supplier cover sheet").Range("b5").Value
                     
        .ChangeFileAccess xlReadOnly
        Kill .FullName
        .Close False
    End With
    Application.ScreenUpdating = True
 
Upvote 0
Yes, because you did not explicitly reference which workbook to copy/pastespecial/values to, so it uses the workbook before it's copied. Try changing it around ..

Code:
    Dim wb As Workbook
    Dim strdate As String, strPath as String
    strdate = Format(Now, "mm-dd-yy")
    Application.ScreenUpdating = False
    Sheets(Array("8d supplier cover sheet", "#5035e")).Copy
    Set wb = ActiveWorkbook
    wb.Sheets(1).Cells.Copy wb.Sheets(1).Cells.PasteSpecial(xlPasteValues)
    Application.CutCopyMode = False

    With wb
        .SaveAs "Scar Report - " & Sheets("8d supplier cover sheet").Range("b5").Value & ".xls"
        .ChangeFileAccess xlReadOnly
        .SendMail Sheets("8d supplier cover sheet").Range("j1").Value, _
                     "Scar Number: " & Sheets("8d supplier cover sheet").Range("b5").Value
        strPath = .FullName
        .Close False
        Kill .strPath
    End With
    Application.ScreenUpdating = True
 
Upvote 0
Well I finally got the sheets to send and save correctly but and error occurs at:

Kill .strPath

error:
Run-Time Error 424 "Object required"

thanks a lot for taking the time to help me with this!!!
 
Upvote 0

Forum statistics

Threads
1,203,728
Messages
6,057,004
Members
444,902
Latest member
ExerciseInFutility

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top