Solved

Save Excel worksheet as html

Posted on 2011-09-02
7
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 83

Expert Comment

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

Expert Comment

by:SANTABABY
ID: 36476237
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
ID: 36476246
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:sandramac
ID: 36476278
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
ID: 36476287
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
ID: 36476444
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
ID: 36486983
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

636 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