Code for copying to new workbook--2007 issue

froggiebeckie

Board Regular
Joined
Sep 27, 2002
Messages
87
I've been using some code to copy the active sheet and send it as an attachment in Outlook. Everything was working fine, and then Along Came Excel 2007.

I did a bit of debugging (change in file locations, etc.) and all seemed to be right with the world, but of course, it couldn't be that easy.
The version that is created can't be opened by most folks, giving the "unrecognized format" error, even though it has the correct .xls extension.
I can manually copy the active sheet to a new wb, save it as 97-2003 version and send it through Outlook and everything is fine.
Any idea why I can't do it through code anymore?

Here's the code. The relevant portion starts with 'Make a copy of...:

Sub EmailWithOutlook()
'Variable declaration
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String

'Turn off screen updating
Application.ScreenUpdating = False

'Make a copy of the active sheet and save it to
'a temporary file
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = "Vac Sched.xls"
On Error Resume Next
Kill "c:\Documents and Settings\Desktop\" & FileName
On Error GoTo 0
WB.SaveAs FileName:="C:\Documents and Settings\Desktop\" & FileName

'Create and show the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
'Uncomment the line below to hard code a recipient
.To= ";APPROPRIATE ADDRESSES"

'Uncomment the line below to hard code a subject
.Subject = "Current Vac Sched.!"
.Attachments.Add WB.FullName
.Display
End With

'Delete the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False

'Restore screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub

Thanks in advance,
BeckieO
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
POOOOO, Brain dead moment here.
I realized, all I needed to do was add the formatting info (, FileFormat:=xlExcel8) so that the line reads:

WB.SaveAs FileName:="C:\Documents and Settings\Desktop\" & FileName
, FileFormat:=xlExcel8

Anyway, thanks for looking and maybe this will help someone else.

BeckieO
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

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