ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Problem with macro to email xls (https://www.excelbanter.com/excel-discussion-misc-queries/147045-problem-macro-email-xls.html)

hnyb1

Problem with macro to email xls
 
Hi, I've been using a macro to automatically send Excel worksheets to
specific email addresses on quite a few files I have set up. I just added
this macro to a spreadsheet that has some merged cells that are used for
notes. I realized after I began using the macro that any text typed into the
merged cell beyond 250 characters is deleted when the worksheet is emailed
using the macro. I don't believe this is a problem with the code, but I am
including it below to make sure. Is there any work around for this?

Sub Mail_ActiveSheet_PR()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & Sheets("Dom. Parts Order Req").Range("D11").Value &
" Approved.xls"
.SendMail ", Sheets("Dom. Parts Order
Req").Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Holly

Ron de Bruin

Problem with macro to email xls
 
The only thing you can do to avoid this Excel bug (btw: fixed in excel 2007) is to
to add a new workbook with one sheet and copy all cells from your sheet in this workbook

Sub Mail_ActiveSheet_PR()
Dim ws As Worksheet
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set ws = ActiveSheet
Set wb = Workbooks.Add(1)
ws.Cells.Copy wb.Sheets(1).Cells(1)
ws.Name = "Dom. Parts Order Req"

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Hi, I've been using a macro to automatically send Excel worksheets to
specific email addresses on quite a few files I have set up. I just added
this macro to a spreadsheet that has some merged cells that are used for
notes. I realized after I began using the macro that any text typed into the
merged cell beyond 250 characters is deleted when the worksheet is emailed
using the macro. I don't believe this is a problem with the code, but I am
including it below to make sure. Is there any work around for this?

Sub Mail_ActiveSheet_PR()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & Sheets("Dom. Parts Order Req").Range("D11").Value &
" Approved.xls"
.SendMail ", Sheets("Dom. Parts Order
Req").Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Holly


hnyb1

Problem with macro to email xls
 
Thanks, Ron.

This worked perfectly. One more question, though. Anyway this can be made
to work on emailing 2 worksheets in a workbook?

Thanks again,
Holly

"Ron de Bruin" wrote:

The only thing you can do to avoid this Excel bug (btw: fixed in excel 2007) is to
to add a new workbook with one sheet and copy all cells from your sheet in this workbook

Sub Mail_ActiveSheet_PR()
Dim ws As Worksheet
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set ws = ActiveSheet
Set wb = Workbooks.Add(1)
ws.Cells.Copy wb.Sheets(1).Cells(1)
ws.Name = "Dom. Parts Order Req"

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Hi, I've been using a macro to automatically send Excel worksheets to
specific email addresses on quite a few files I have set up. I just added
this macro to a spreadsheet that has some merged cells that are used for
notes. I realized after I began using the macro that any text typed into the
merged cell beyond 250 characters is deleted when the worksheet is emailed
using the macro. I don't believe this is a problem with the code, but I am
including it below to make sure. Is there any work around for this?

Sub Mail_ActiveSheet_PR()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & Sheets("Dom. Parts Order Req").Range("D11").Value &
" Approved.xls"
.SendMail ", Sheets("Dom. Parts Order
Req").Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Holly



Ron de Bruin

Problem with macro to email xls
 
Try this one for "sheet1" and "sheet3"

Sub Mail_ActiveSheet_PR()
Dim i As Integer
Dim sh As Worksheet
Dim wb1 As Workbook
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set wb1 = ThisWorkbook
Set wb = Workbooks.Add(1)
wb.Worksheets.Add after:=wb.Sheets(1)

i = 0

For Each sh In wb1.Sheets(Array("Sheet1", "Sheet3"))
i = i + 1
sh.Cells.Copy wb.Sheets(i).Cells(1)
Next sh

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Thanks, Ron.

This worked perfectly. One more question, though. Anyway this can be made
to work on emailing 2 worksheets in a workbook?

Thanks again,
Holly

"Ron de Bruin" wrote:

The only thing you can do to avoid this Excel bug (btw: fixed in excel 2007) is to
to add a new workbook with one sheet and copy all cells from your sheet in this workbook

Sub Mail_ActiveSheet_PR()
Dim ws As Worksheet
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set ws = ActiveSheet
Set wb = Workbooks.Add(1)
ws.Cells.Copy wb.Sheets(1).Cells(1)
ws.Name = "Dom. Parts Order Req"

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Hi, I've been using a macro to automatically send Excel worksheets to
specific email addresses on quite a few files I have set up. I just added
this macro to a spreadsheet that has some merged cells that are used for
notes. I realized after I began using the macro that any text typed into the
merged cell beyond 250 characters is deleted when the worksheet is emailed
using the macro. I don't believe this is a problem with the code, but I am
including it below to make sure. Is there any work around for this?

Sub Mail_ActiveSheet_PR()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & Sheets("Dom. Parts Order Req").Range("D11").Value &
" Approved.xls"
.SendMail ", Sheets("Dom. Parts Order
Req").Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Holly



Ron de Bruin

Problem with macro to email xls
 
This one is easier and also have the correct sheet names

Sub Mail_ActiveSheet_PR()
Dim sh As Worksheet
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set wb1 = ThisWorkbook

wb1.Sheets(Array("Sheet1", "Sheet3")).Copy
Set wb2 = ActiveWorkbook

For Each sh In wb2.Worksheets
wb1.Sheets(sh.Name).Cells.Copy wb2.Sheets(sh.Name).Cells(1)
Next sh

With wb2
.SaveAs "C:\" & wb2.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb2.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Ron de Bruin" wrote in message ...
Try this one for "sheet1" and "sheet3"

Sub Mail_ActiveSheet_PR()
Dim i As Integer
Dim sh As Worksheet
Dim wb1 As Workbook
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set wb1 = ThisWorkbook
Set wb = Workbooks.Add(1)
wb.Worksheets.Add after:=wb.Sheets(1)

i = 0

For Each sh In wb1.Sheets(Array("Sheet1", "Sheet3"))
i = i + 1
sh.Cells.Copy wb.Sheets(i).Cells(1)
Next sh

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Thanks, Ron.

This worked perfectly. One more question, though. Anyway this can be made
to work on emailing 2 worksheets in a workbook?

Thanks again,
Holly

"Ron de Bruin" wrote:

The only thing you can do to avoid this Excel bug (btw: fixed in excel 2007) is to
to add a new workbook with one sheet and copy all cells from your sheet in this workbook

Sub Mail_ActiveSheet_PR()
Dim ws As Worksheet
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set ws = ActiveSheet
Set wb = Workbooks.Add(1)
ws.Cells.Copy wb.Sheets(1).Cells(1)
ws.Name = "Dom. Parts Order Req"

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Hi, I've been using a macro to automatically send Excel worksheets to
specific email addresses on quite a few files I have set up. I just added
this macro to a spreadsheet that has some merged cells that are used for
notes. I realized after I began using the macro that any text typed into the
merged cell beyond 250 characters is deleted when the worksheet is emailed
using the macro. I don't believe this is a problem with the code, but I am
including it below to make sure. Is there any work around for this?

Sub Mail_ActiveSheet_PR()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & Sheets("Dom. Parts Order Req").Range("D11").Value &
" Approved.xls"
.SendMail ", Sheets("Dom. Parts Order
Req").Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Holly


hnyb1

Problem with macro to email xls
 
Thank you so much! This is excellent.

"Ron de Bruin" wrote:

This one is easier and also have the correct sheet names

Sub Mail_ActiveSheet_PR()
Dim sh As Worksheet
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set wb1 = ThisWorkbook

wb1.Sheets(Array("Sheet1", "Sheet3")).Copy
Set wb2 = ActiveWorkbook

For Each sh In wb2.Worksheets
wb1.Sheets(sh.Name).Cells.Copy wb2.Sheets(sh.Name).Cells(1)
Next sh

With wb2
.SaveAs "C:\" & wb2.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb2.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Ron de Bruin" wrote in message ...
Try this one for "sheet1" and "sheet3"

Sub Mail_ActiveSheet_PR()
Dim i As Integer
Dim sh As Worksheet
Dim wb1 As Workbook
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set wb1 = ThisWorkbook
Set wb = Workbooks.Add(1)
wb.Worksheets.Add after:=wb.Sheets(1)

i = 0

For Each sh In wb1.Sheets(Array("Sheet1", "Sheet3"))
i = i + 1
sh.Cells.Copy wb.Sheets(i).Cells(1)
Next sh

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Thanks, Ron.

This worked perfectly. One more question, though. Anyway this can be made
to work on emailing 2 worksheets in a workbook?

Thanks again,
Holly

"Ron de Bruin" wrote:

The only thing you can do to avoid this Excel bug (btw: fixed in excel 2007) is to
to add a new workbook with one sheet and copy all cells from your sheet in this workbook

Sub Mail_ActiveSheet_PR()
Dim ws As Worksheet
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")

Application.ScreenUpdating = False

Set ws = ActiveSheet
Set wb = Workbooks.Add(1)
ws.Cells.Copy wb.Sheets(1).Cells(1)
ws.Name = "Dom. Parts Order Req"

With wb
.SaveAs "C:\" & wb.Sheets(1).Range("D11").Value & " Approved.xls"
.SendMail ", wb.Sheets(1).Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
Hi, I've been using a macro to automatically send Excel worksheets to
specific email addresses on quite a few files I have set up. I just added
this macro to a spreadsheet that has some merged cells that are used for
notes. I realized after I began using the macro that any text typed into the
merged cell beyond 250 characters is deleted when the worksheet is emailed
using the macro. I don't believe this is a problem with the code, but I am
including it below to make sure. Is there any work around for this?

Sub Mail_ActiveSheet_PR()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "yymmdd")
Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "C:\" & Sheets("Dom. Parts Order Req").Range("D11").Value &
" Approved.xls"
.SendMail ", Sheets("Dom. Parts Order
Req").Range("D11").Value
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
End Sub

Thanks,
Holly




All times are GMT +1. The time now is 12:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com