Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba-Excel: Select content of HTML-page in FrontPage?

Status
Not open for further replies.

rudo

Programmer
Jul 3, 2002
72
0
0
NL
Hi,

For a vba Excel macro I try to find the code to select the content of a html-page in FrontPage (in order to replace it with the content of the clipboard). The explanations on the website of MS are not clear enough for me. An example would be great.

The Excel-macro opens a txt-file in Word containing new html-code for the webpage. (This code has been composed by another macro.) Then it copies the new code to the clipboard and must past it over the content of the html-file that is opened in Frontpage.

This is the code I have so far:

Code:
Sub ReplaceHTML()

    'Replace html of a .htm-file in FrontPage
    'by html saved in a .txt-file
    
    'for Word:
    Dim MyPath As String
    Dim myDoc As String

    'for the following instructions activate Tools, References, Frontpage
    
    'for frontpage:
    Dim myWeb As WebEx
    Dim myFiles As WebFiles
    Dim myFile As WebFile
    Dim myFileToChange As String
    Dim myMessage As String
    Dim myFileName As String
    
    'for selecting code view:
    Dim fpApp As FrontPage.Application
    Dim objPage As PageWindowEx
    
    'for selecting page content in FP:
    Dim objSearch As SearchInfo
    Dim blnFound As Boolean
    Dim objRange As IHTMLTxtRange
    
    'open the txt.file with the new html-code in Word
    
    Set WrdApp = CreateObject("Word.Application")
    WrdApp.Visible = True
    MyPath = "C:\Workshop\"
    myDoc = "new_code.txt"
    Set WrdDoc = WrdApp.Documents.Open(MyPath & myDoc)
    
    'copy new HTML into clipboard
    
    WrdApp.Windows(myDoc).Activate
    WrdApp.Selection.WholeStory
    WrdApp.Selection.Copy

    'FrontPage must be open in advance
    
    Set fpApp = FrontPage.Application
    Set myWeb = ActiveWeb
    Set myFiles = myWeb.RootFolder.Files

    myFileToChange = "old_code.htm"

    'close all webfiles in FrontPage
    
    With myWeb
        For Each myFile In myFiles
            If Not fpApp.ActivePageWindow Is Nothing Then
               fpApp.ActivePageWindow.Close ForceSave:=False
            End If
        Next myFile
        
        'open webfile to change

        For Each myFile In myFiles
            myFileName = myFile.Name
            If myFileName = myFileToChange Then
                myFile.Open
                'select HTML code view
                Set objPage = fpApp.ActivePageWindow
               If objPage.ViewMode <> 2 Then objPage.ViewMode = 2
                
                objPage.Activate
        
'Here: How to select the whole page and paste the content of the clipboard over it?
                
                objPage.Close True
                
                Exit For
           End If
        Next
    End With
End Sub

If you can help, thank you very much in advance!
 
This works for me:

Code:
Sub ReplaceHTML()

    'Replace html of a .htm-file in FrontPage
    'by html saved in a .txt-file
    
    'for Word:
    Dim MyPath As String
    Dim myDoc As String

    'for the following instructions activate Tools, References, Frontpage
    
    'for frontpage:
    Dim myWeb As WebEx
    Dim myFiles As WebFiles
    Dim myFile As WebFile
    Dim myFileToChange As String
    Dim myMessage As String
    Dim myFileName As String
    
    'for selecting code view:
    Dim fpApp As FrontPage.Application
    Dim objPage As PageWindowEx
    
    'for selecting page content in FP:
    Dim objSearch As SearchInfo
    Dim blnFound As Boolean
    Dim objRange As IHTMLTxtRange
    
    'open the txt.file with the new html-code in Word
    
    Set WrdApp = CreateObject("Word.Application")
    WrdApp.Visible = True
    MyPath = "C:\Workshop\"
    myDoc = "new_code.txt"
    Set WrdDoc = WrdApp.Documents.Open(MyPath & myDoc)
    
    'copy new HTML into clipboard
    
    WrdApp.Windows(myDoc).Activate
    WrdApp.Selection.WholeStory
    WrdApp.Selection.Copy

    'FrontPage must be open in advance
    
    Set fpApp = FrontPage.Application
    Set myWeb = ActiveWeb
    Set myFiles = myWeb.RootFolder.Files

    myFileToChange = "old_code.htm"

    'close all webfiles in FrontPage
    
    With myWeb
        For Each myFile In myFiles
            If Not fpApp.ActivePageWindow Is Nothing Then
               fpApp.ActivePageWindow.Close ForceSave:=False
            End If
        Next myFile
        
        'open webfile to change

        For Each myFile In myFiles
            myFileName = myFile.Name
            If myFileName = myFileToChange Then
                myFile.Open
                'select HTML code view
                Set objPage = fpApp.ActivePageWindow
               If objPage.ViewMode <> 2 Then objPage.ViewMode = 2
                
                fpApp.ActivePageWindow.Activate

                fpApp.CommandBars("Edit").Controls(9).Execute
                fpApp.CommandBars("Edit").Controls(6).Execute
                
                    'note: if you use an English version
                    'you can probably replace 9 by "Select all"
                    'and replace 6 by "Paste"
                
                myFile.Close True
                
                Exit For
           End If
        Next
    End With
End Sub


see also:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top