FP2000: How to Apply Styles to Pages by Using VBA
ID: Q242336
|
The information in this article applies to:
SUMMARY
By using Visual Basic for Applications code in FrontPage 2000, you can programmatically add code to multiple pages.
With this sample VBA macro, you can embed a style sheet that removes the underline from the hyperlinks in all the pages in your web.
For more information about using the sample code in this article, click
the article number below to view the article in the Microsoft Knowledge
Base:
Q212536
OFF2000: How to Run Sample Code from Knowledge Base Articles
MORE INFORMATION
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
Sample Macro to Remove Underlines from Hyperlinks
To run this macro, copy the code to the Visual Basic Editor in FrontPage and run the myProcedure macro.
Sub myProcedure()
'Set up a variable to hold the result of a message box
Dim myMsgBoxResults As VbMsgBoxResult
'Check to see if a web is open.
If ActiveWebWindow.Web Is Nothing Then
'If no web is open, display a message box.
MsgBox "Please open a web before running this macro.", _
vbOKOnly + vbExclamation
'. . . and end the macro.
Exit Sub
End If
'//////////////////////////////////////////////////////////////////
'In order for us to update the HTML in our files, there must be no
'pages open. To check for this, we check the Count property of
'the PageWindows collection. The PageWindows collection's Count
'property is equal to the number of files that are currently open.
'//////////////////////////////////////////////////////////////////
'Get the count of the PageWindows collection
If ActiveWeb.ActiveWebWindow.PageWindows.Count <> 0 Then
'Assign the result of a message box to the variable
myMsgBoxResults = _
MsgBox("Please close all files before running this macro.", _
vbOKOnly + vbExclamation)
'If the user clicks OK in our message box, exit the macro.
'This variable will equal vbOK as soon as the user clicks
'the OK button in the message box.
If myMsgBoxResults = vbOK Then Exit Sub
End If
'Set up a variable for the WebFolder we're passing to the
'RemoveUnderline procedure
Dim myTempFolder As WebFolder
'Set the myWebFolder variable to equal the rootfolder of
'the active web
Set myTempFolder = ActiveWeb.RootFolder
'Now call the RemoveUnderline procedure and pass myWebFolder to it.
RemoveUnderline myTempFolder
'Display a dialog saying we're done.
myMsgBoxResults = MsgBox _
("Embedded style sheet added to all pages.", vbOKOnly + vbInformation)
End Sub
Sub RemoveUnderline(myWebFolder As WebFolder)
'Set up variables
Dim myFiles As WebFiles
Dim myFile As WebFile
Dim myStyleSheet As FPHTMLStyleSheet
Dim myStyleTags As String
'Set myFiles to the active web's Files collection
Set myFiles = myWebFolder.Files
'Set myFolders to the active web's Folders collection
Set myFolders = myWebFolder.Folders
For Each myFile In myFiles
'Check to see if the file is actually an ASP or HTML file
If UCase(myFile.Extension) = "HTM" Or _
UCase(myFile.Extension) = "HTML" Or _
UCase(myFile.Extension) = "ASP" Then
'Open the file
myFile.Open
'Set up variable for the opened PageWindow
Dim myPage As PageWindow
Set myPage = ActivePageWindow
'Make sure we're in Normal view.
myPage.ViewMode = fpPageViewNormal
'add a styles sheet if one doesn't already exist
If ActiveDocument.styleSheets.Length < 1 Then
'Assign a value to myStyleTags
myStyleTags = "<style>" & vbCrLf & "</style>"
'Insert the empty style sheet in the head of the document
Call ActiveDocument.all.tags("head"). _
Item(0).insertAdjacentHTML("BeforeEnd", myStyleTags)
End If
'Set myStyleSheet to refer to the style sheet
Set myStyleSheet = ActiveDocument.styleSheets(0)
'Add our rule to the style sheet
Call myStyleSheet.addRule("a", "{text-decoration: none};")
'Save and close the page
myPage.save
myPage.Close
End If
Next myFile
'Now loop through all of the subfolders by calling the procedure recursively
Dim mySubFolder As WebFolder
For Each mySubFolder In myWebFolder.Folders
'Only if the current subfolder is not a subweb
If mySubFolder.IsWeb = False Then RemoveUnderline mySubFolder
Next mySubFolder
End Sub
Additional query words:
vba VB fp2k
Keywords :
Version : WINDOWS:
Platform : WINDOWS
Issue type :