Solved

HTML Page On The Fly via VBA

Posted on 2012-03-14
2
223 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
Comment Utility
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
Comment Utility
* 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

743 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

13 Experts available now in Live!

Get 1:1 Help Now