Solved

Save Excel worksheet as html

Posted on 2011-09-02
7
165 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:sandramac
  • 4
  • 2
7 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
'sheet5.z71' won't be recognized as an 'htm' file,  maybe 'sheet5.z71.htm'.
0
 
LVL 10

Expert Comment

by:SANTABABY
Comment Utility
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.)
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

Open in new window

0
 
LVL 10

Expert Comment

by:SANTABABY
Comment Utility
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:sandramac
Comment Utility
yes sheet 5 cell Z71 the value will be a text like KTUY  so it would save as KTUY.htm
0
 
LVL 10

Expert Comment

by:SANTABABY
Comment Utility
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.
0
 

Author Comment

by:sandramac
Comment Utility
Hello, it is working, just a quick question it saves it as a .mht, can it be save as .htm
0
 
LVL 10

Accepted Solution

by:
SANTABABY earned 500 total points
Comment Utility
First try this:
In the VBA subroutine, replace the line
SaveFileName = SaveDir & Worksheets(5).Range("$Z$71")

Open in new window

with
SaveFileName = SaveDir & Worksheets(5).Range("$Z$71") & ".htm"

Open in new window



(The above worked for me in EXCEL 2007) If it does not work for you, please try the following
In Line #8, please replace
xlHtmlStatic

Open in new window

with
xlHtml

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now