Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default sending one sheet by e-mail

Excel '97

This is what I am trying to do:

With my file open - add a new sheet, copy stuff onto it,
move that sheet into a new file and then send that file
in .csv format.

The code below works fine but asks "Do you want to save
changes before switching file status?"

Sub Createandsendfile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim wb As Workbook
'Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets.Add

' code to add data to the new sheet from several sheets in
the file
' new sheet is then put in a new file

ActiveSheet.Move
Set wb = ActiveWorkbook
With wb
..SaveAs FileName:="my new file", FileFormat:=xlCSV
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
..To = "
..Subject = "e-mail subject"
..Attachments.Add wb.FullName
..Send
End With
..ChangeFileAccess xlReadOnly
Kill .FullName
..Close False
End With
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
'Application.DisplayAlerts = True
End Sub

I put displayalerts to false but then the SaveAs dialog
box is displayed.

Can anyone please help?

Gareth
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default sending one sheet by e-mail

I have found out what the problem is but cannot fix it
myself.

The problem is switching from .xls to .csv!

Gareth

-----Original Message-----
Excel '97

This is what I am trying to do:

With my file open - add a new sheet, copy stuff onto it,
move that sheet into a new file and then send that file
in .csv format.

The code below works fine but asks "Do you want to save
changes before switching file status?"

Sub Createandsendfile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim wb As Workbook
'Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets.Add

' code to add data to the new sheet from several sheets

in
the file
' new sheet is then put in a new file

ActiveSheet.Move
Set wb = ActiveWorkbook
With wb
..SaveAs FileName:="my new file", FileFormat:=xlCSV
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
..To = "
..Subject = "e-mail subject"
..Attachments.Add wb.FullName
..Send
End With
..ChangeFileAccess xlReadOnly
Kill .FullName
..Close False
End With
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
'Application.DisplayAlerts = True
End Sub

I put displayalerts to false but then the SaveAs dialog
box is displayed.

Can anyone please help?

Gareth
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default sending one sheet by e-mail

Hi Gareth

Use this

This example send the activesheet
You can change it to your situation

Sub Createandsendfile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim wb As Workbook
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
..SaveAs Filename:="c:\my new file", FileFormat:=xlCSV
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
..To = "
..Subject = "e-mail subject"
..Attachments.Add wb.FullName
..display
End With
..Close False
Kill "c:\my new file.csv"
End With
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"gareth" wrote in message ...
Excel '97

This is what I am trying to do:

With my file open - add a new sheet, copy stuff onto it,
move that sheet into a new file and then send that file
in .csv format.

The code below works fine but asks "Do you want to save
changes before switching file status?"

Sub Createandsendfile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim wb As Workbook
'Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets.Add

' code to add data to the new sheet from several sheets in
the file
' new sheet is then put in a new file

ActiveSheet.Move
Set wb = ActiveWorkbook
With wb
.SaveAs FileName:="my new file", FileFormat:=xlCSV
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "
.Subject = "e-mail subject"
.Attachments.Add wb.FullName
.Send
End With
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
'Application.DisplayAlerts = True
End Sub

I put displayalerts to false but then the SaveAs dialog
box is displayed.

Can anyone please help?

Gareth



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default sending one sheet by e-mail

Sub Createandsendfile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim wb As Workbook, sName as String
'Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets.Add

' code to add data to the new sheet from several sheets in
the file
' new sheet is then put in a new file

ActiveSheet.Move
Set wb = ActiveWorkbook
With wb
..SaveAs FileName:="my new file", FileFormat:=xlCSV
sName = .FullName
..Close SaveChanges:=False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
..To = "
..Subject = "e-mail subject"
..Attachments.Add sName
..Send
End With
Kill sName
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
'Application.DisplayAlerts = True
End Sub

--
Regards,
Tom Ogilvy


"gareth" wrote in message
...
Excel '97

This is what I am trying to do:

With my file open - add a new sheet, copy stuff onto it,
move that sheet into a new file and then send that file
in .csv format.

The code below works fine but asks "Do you want to save
changes before switching file status?"

Sub Createandsendfile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim wb As Workbook
'Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets.Add

' code to add data to the new sheet from several sheets in
the file
' new sheet is then put in a new file

ActiveSheet.Move
Set wb = ActiveWorkbook
With wb
.SaveAs FileName:="my new file", FileFormat:=xlCSV
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "
.Subject = "e-mail subject"
.Attachments.Add wb.FullName
.Send
End With
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
'Application.DisplayAlerts = True
End Sub

I put displayalerts to false but then the SaveAs dialog
box is displayed.

Can anyone please help?

Gareth



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending a blank e-mail Hawksby Excel Discussion (Misc queries) 1 September 25th 07 09:16 AM
Sending one sheet by mail Robert Excel Discussion (Misc queries) 1 June 18th 06 10:43 AM
General mail failure when sending e-mail from Excel Adrienne Excel Discussion (Misc queries) 5 November 4th 05 12:59 PM
Sending E-mail litew_8 Excel Worksheet Functions 1 November 21st 04 06:13 AM
Sending files by e-mail Gareth[_3_] Excel Programming 5 November 3rd 03 02:54 PM


All times are GMT +1. The time now is 10:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"