sandramac
asked on
Save Excel worksheet as html
Hello, trying to build a vba code to save sheet 14 range A1:P51 as a .htm file, using the value of sheet5.z71 as the filename.
'sheet5.z71' won't be recognized as an 'htm' file, maybe 'sheet5.z71.htm'.
Please try the following subroutine.
(Note that : Exception conditions such as sheet 5 or 14 do not exist, are not handled. Addition code can be added to handle those conditions.)
(Note that : Exception conditions such as sheet 5 or 14 do not exist, are not handled. Addition code can be added to handle those conditions.)
Sub SaveAsHtml()
SaveDir = "" 'Target directory, end with a \
SaveFileName = SaveDir & Worksheets(5).Range("$Z$71")
WSname = Worksheets(14).Name
Src = "$A$1:$P$51"
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, SaveFileName, WSname, Src, xlHtmlStatic, WSname & "_DIV", "")
.Publish (True)
.AutoRepublish = False
End With
End Sub
Assumed that you wanted to use the value in Cell Z71 of sheet5 as the name of the file to be generated. If that's not what you meant, please let me know.
ASKER
yes sheet 5 cell Z71 the value will be a text like KTUY so it would save as KTUY.htm
Please try to run the code above and please confirm whether it works for you or if you need any assistance to make it work for you.
ASKER
Hello, it is working, just a quick question it saves it as a .mht, can it be save as .htm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.