ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Code - Saving excel workbook as a web page (https://www.excelbanter.com/excel-programming/408994-vbulletin-code-saving-excel-workbook-web-page.html)

[email protected]

VB Code - Saving excel workbook as a web page
 
Hi - I am using the following code to save a workbook, attach it to an
Outlook email and send. I would like to save the workbook as a web
page and attach it. The code works and saves the file as .htm and
attaches it to an email message, but when I open the file from the
message its all coded. Can someone tell me what I'm doing wrong?

Sub EMAIL()
Set WB = ActiveWorkbook
Filename = "Projects.htm"
On Error Resume Next
Kill "H:\" & Filename
On Error GoTo 0
WB.SaveAs Filename:="H:\" & Filename
FileFormat = xlHtm

'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 = "
'Uncomment the line below to hard code a subject
.Subject = "Parts Due"
.Attachments.Add WB.FullName
.Display
End With

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

End Sub

joel

VB Code - Saving excel workbook as a web page
 
The code below will correct you save problem.

Sub EMAIL()
Set WB = ActiveWorkbook
FName = "Projects.htm"
On Error Resume Next
Kill "H:" & FName
On Error GoTo 0
ActiveWorkbook.SaveAs _
Filename:="C:\temp\" & FName, _
FileFormat:=xlHtml


" wrote:

Hi - I am using the following code to save a workbook, attach it to an
Outlook email and send. I would like to save the workbook as a web
page and attach it. The code works and saves the file as .htm and
attaches it to an email message, but when I open the file from the
message its all coded. Can someone tell me what I'm doing wrong?

Sub EMAIL()
Set WB = ActiveWorkbook
Filename = "Projects.htm"
On Error Resume Next
Kill "H:\" & Filename
On Error GoTo 0
WB.SaveAs Filename:="H:\" & Filename
FileFormat = xlHtm

'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 = "
'Uncomment the line below to hard code a subject
.Subject = "Parts Due"
.Attachments.Add WB.FullName
.Display
End With

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

End Sub



All times are GMT +1. The time now is 03:46 AM.

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