Solved

HTML Page On The Fly via VBA

Posted on 2012-03-14
2
226 Views
Last Modified: 2012-08-14
Hello Everyone
   Is there a way to create an basic web page via VBA without creating a notepad doc and saving it?

Sample:

<!DOCTYPE html>
<html>
     <body>
         <p>Hello World</p>
   </body>
</html>

If so could you provide an example?
0
Comment
Question by:Friggin_Lazy
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37722950
You would have to save/create the file somehow.

If you don't want to use Notepad*  you could just use VBA file I/O functions to create the file.

Something like this perhaps.
Sub CreateHTMLDoc()
Dim strFilename As String
Dim strHTML As String
Dim FF As Integer

    strFilename = "C:\testdoc.html"
    
    strHTML = "<!DOCTYPE html><html>     <body>         <p>Hello World</p>   </body></html>"

    FF = FreeFile
    
    Open strFilename For Output As #FF
    
        Print #FF, strHTML
        
    Close #FF
    
    ThisWorkbook.FollowHyperlink strFilename
    
End Sub

Open in new window


The HTML is hardcoded in one string but you could easily build it using VBA functions.

* Not actually sure how you would use Notepad to create an HTML document from VBA.
0
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 37723103
* Not actually sure how you would use Notepad to create an HTML document from VBA.
Just write to a notepad text file, can be any .txt file, then just change the extension to .htm, which you can use the Name method for that.  I don't know why you would want to, when you can just write to a .htm file, like the method you've shown.

Regards,
Zack Barresse
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
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…

808 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