Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Save Excel worksheet as html

Posted on 2011-09-02
7
Medium Priority
?
172 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 84

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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

715 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