G
Guest
Hi
I am using excel 2000 and am trying to automatically send an email on a button press, button is called status update
on the press of this button it should unhide columns K-S select 4 cells O12,013,014,015 all with formulas of =m12 through 15 in. I then need this to be copied and paste as values into an email and sent. I then need the macro to rehide the columns and return to cell a1 in the sheet. I have tried adapting Ron de Bruins code as below but get a debug error. Any help would be greatly appreciate
Sub Mail_Selection_Outlook_Body(
'Is not working in Office 9
Dim source As Rang
Dim dest As Workboo
Dim myshape As Shap
Dim OutApp As Outlook.Applicatio
Dim OutMail As Outlook.MailIte
Set source = Nothin
On Error Resume Nex
Set source = Selection.Range("o1215"
Cells.Cop
Cells.PasteSpecial xlPasteValue
Cells(1).Selec
Application.CutCopyMode = Fals
On Error GoTo
If source Is Nothing The
MsgBox "The selection is not a range or the sheet is protect, please correct and try again.", vbOKOnl
Exit Su
End I
If ActiveWindow.SelectedSheets.Count > 1 Or
Selection.Cells.Count = 1 Or
Selection.Areas.Count > 1 The
MsgBox "An Error occurred :" & vbNewLine & vbNewLine &
"You have more than one sheet selected." & vbNewLine &
"You only selected one cell." & vbNewLine &
"You selected more than one area." & vbNewLine & vbNewLine &
"Please correct and try again.", vbOKOnl
Exit Su
End I
Application.ScreenUpdating = Fals
ActiveSheet.Cop
Set dest = ActiveWorkboo
For Each myshape In dest.Sheets(1).Shape
myshape.Delet
Nex
Set OutApp = CreateObject("Outlook.Application"
Set OutMail = OutApp.CreateItem(olMailItem
With OutMai
.To = "email adress witheld
.CC = "
.BCC = "
.Subject = "This is the Subject line
.HTMLBody = RangetoHTM
.Send 'or use .Displa
End Wit
dest.Close Fals
Set OutMail = Nothin
Set OutApp = Nothin
Set dest = Nothin
Application.ScreenUpdating = Tru
End Su
Function RangetoHTML(
Dim fso As Objec
Dim ts As Objec
Dim TempFile As Strin
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm
With ActiveWorkbook.PublishObjects.Add(
SourceType:=xlSourceRange,
Filename:=TempFile,
Sheet:=ActiveSheet.Name,
source:=Selection.Address,
HtmlType:=xlHtmlStatic
.Publish (True
End Wit
Set fso = CreateObject("Scripting.FileSystemObject"
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2
RangetoHTML = ts.ReadAl
ts.Clos
Set ts = Nothin
Set fso = Nothin
Kill TempFil
End Functio
I am using excel 2000 and am trying to automatically send an email on a button press, button is called status update
on the press of this button it should unhide columns K-S select 4 cells O12,013,014,015 all with formulas of =m12 through 15 in. I then need this to be copied and paste as values into an email and sent. I then need the macro to rehide the columns and return to cell a1 in the sheet. I have tried adapting Ron de Bruins code as below but get a debug error. Any help would be greatly appreciate
Sub Mail_Selection_Outlook_Body(
'Is not working in Office 9
Dim source As Rang
Dim dest As Workboo
Dim myshape As Shap
Dim OutApp As Outlook.Applicatio
Dim OutMail As Outlook.MailIte
Set source = Nothin
On Error Resume Nex
Set source = Selection.Range("o1215"
Cells.Cop
Cells.PasteSpecial xlPasteValue
Cells(1).Selec
Application.CutCopyMode = Fals
On Error GoTo
If source Is Nothing The
MsgBox "The selection is not a range or the sheet is protect, please correct and try again.", vbOKOnl
Exit Su
End I
If ActiveWindow.SelectedSheets.Count > 1 Or
Selection.Cells.Count = 1 Or
Selection.Areas.Count > 1 The
MsgBox "An Error occurred :" & vbNewLine & vbNewLine &
"You have more than one sheet selected." & vbNewLine &
"You only selected one cell." & vbNewLine &
"You selected more than one area." & vbNewLine & vbNewLine &
"Please correct and try again.", vbOKOnl
Exit Su
End I
Application.ScreenUpdating = Fals
ActiveSheet.Cop
Set dest = ActiveWorkboo
For Each myshape In dest.Sheets(1).Shape
myshape.Delet
Nex
Set OutApp = CreateObject("Outlook.Application"
Set OutMail = OutApp.CreateItem(olMailItem
With OutMai
.To = "email adress witheld
.CC = "
.BCC = "
.Subject = "This is the Subject line
.HTMLBody = RangetoHTM
.Send 'or use .Displa
End Wit
dest.Close Fals
Set OutMail = Nothin
Set OutApp = Nothin
Set dest = Nothin
Application.ScreenUpdating = Tru
End Su
Function RangetoHTML(
Dim fso As Objec
Dim ts As Objec
Dim TempFile As Strin
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm
With ActiveWorkbook.PublishObjects.Add(
SourceType:=xlSourceRange,
Filename:=TempFile,
Sheet:=ActiveSheet.Name,
source:=Selection.Address,
HtmlType:=xlHtmlStatic
.Publish (True
End Wit
Set fso = CreateObject("Scripting.FileSystemObject"
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2
RangetoHTML = ts.ReadAl
ts.Clos
Set ts = Nothin
Set fso = Nothin
Kill TempFil
End Functio