FP2000: How to Add HTML to a File by Using Visual Basic for Applications

ID: Q238423


The information in this article applies to:
  • Microsoft FrontPage 2000


SUMMARY

The sample code in this article explains how to programmatically insert HTML into a file by using Visual Basic for Applications.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
The following macro assumes that you have a web open in FrontPage and that there is a file in that web called example.htm. After you run this macro, open the example.htm file to see the text that was inserted.

Sub AddHTML()

    ' Set up variables.
    Dim myDocument As FPHTMLDocument
    Dim myFile As WebFile
    Dim myPageWindow As PageWindow
    Dim myTag As IHTMLElement
    Dim myText As String

    ' Set myFile to equal the example.htm file.
    Set myFile = ActiveWeb.RootFolder.Files("example.htm")

    ' Set myPageWindow to equal myFile.
    ' We also use the Edit method to change the view to Normal view
    ' in case the file is opened. In order to insert the HTML, we must
    ' be in Normal view.
    Set myPageWindow = myFile.Edit(fpPageViewNormal)

    ' Set myDocument to equal the document contained in myPageWindow.
    Set myDocument = myPageWindow.Document

    ' Set myTag to equal the first BODY tag.
    ' The All collection referenced here contains a reference to all
    ' HTML tags on the page.
    Set myTag = myDocument.all.tags("body").Item(0)

    ' myText is the text we are going to insert.
    ' The <b> tag makes this text bold.
    myText = "<b>This was inserted with VBA!</b>"
        
    ' Call the insertAdjacentHTML method.
    ' Using this method, we add myText after the beginning BODY tag.
    Call myTag.insertAdjacentHTML("AfterBegin", myText)

    ' Now we save the page. We use the document's original URL.
    myPageWindow.SaveAs myPageWindow.Document.Url

    ' Then we close the page. We append False to this method so that 
    ' the method won't force the page to be saved again.
    myPageWindow.Close False

End Sub 
For more information about using the sample code in this article, please see the following article in the Microsoft Knowledge Base:
Q212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

Additional query words:

Keywords : kbdta
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: September 1, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.