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:
If you can help, thank you very much in advance!
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!