
Originally Posted by
SamT
Dim SINW As Long
SINW = Application.SheetsInNewWorkbook 'Current default
Application.SheetsInNewWorkbook = 1 'Changes current default
Set wb1 = Application.ActiveWorkbook '<--- Original line of code
wb1.ActiveSheet.UsedRange.Copy
Set wb2 = Workbooks.Add
wb2.Sheet1.Cells(1).PasteSpecial Operation:=xlPasteValuesAndNumberFormats
Application.SheetsInNewWorkbook = SINW 'Resets current default
Hi Sam, thanks for the response.
Sorry to be a noob, but how do I implement that into the first part of my code above?
I tried this but it didn't work:
Private Sub commandbutton1_click()
'update 20131209
Dim wb1 As Workbook, wb2 As Workbook
Dim sfilepath As String, sfilename As String
Dim iformat As Integer
Dim SINW As Long
SINW = Application.SheetsInNewWorkbook 'Current default
Application.SheetsInNewWorkbook = 1 'Changes current default
Set wb1 = Application.ActiveWorkbook '<--- Original line of code
wb1.ActiveSheet.UsedRange.Copy
Set wb2 = Workbooks.Add
wb2.Sheet1.Cells(1).PasteSpecial Operation:=xlPasteValuesAndNumberFormats
Application.SheetsInNewWorkbook = SINW 'Resets current default
sfilepath = Environ$("temp")
sfilename = sfilepath & "\ " & wb1.Name
iformat = wb1.FileFormat
wb2.SaveAs sfilename, iformat
wb2.Close
With CreateObject("outlook.application").createitem(0)
.to = Sheet7.Range("G3")
.cc = ""
.bcc = ""
.Subject = Sheet7.Range("A5")
.body = "Hello," & vbLf & vbLf & "Please find attached the YTD third party and time costs." & vbLf & vbLf & "Thanks," & vbLf & "Ray"
.attachments.Add sfilename
.send
End With
Kill sfilename
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub