VB Code - Saving excel workbook as a web page

C

cemorganCO

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 = "(e-mail address removed)"
'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
 
J

Joel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top