Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HTML Page On The Fly via VBA

Posted on 2012-03-14
2
Medium Priority
?
232 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 35

Accepted Solution

by:
Norie earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

886 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