FP2000: How to Set Page Margins by Using VBA (272019)



The information in this article applies to:

  • Microsoft FrontPage 2000

This article was previously published under Q272019

SUMMARY

This article describes how to use Microsoft Visual Basic for Applications (VBA) in Microsoft FrontPage 2000 to set page margins.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. To run this macro, copy the code to the Visual Basic Editor in FrontPage 2000, and then run the SetMargins procedure. This code contains no error checking for the margin settings that are input by the user.
Sub SetMargins()    

'///////////////////////////////////////////////////////////////////////// 
'//  This procedure prompts for the value for the top margin and the left
'//  margin and then calls the ChangeMargins procedure.
'///////////////////////////////////////////////////////////////////////// 

    'Set up variables to hold the top and left margin
    Dim TopMargin As String
    Dim LeftMargin As String
    
    'Use an InputBox to assign the values for the top and left margin
    'A default setting of "0" is specified
    TopMargin = InputBox("Please specify the top margin in pixels:", , 0)
    LeftMargin = InputBox("Please specify the left margin in pixels:", , 0)
    
    'Notice that the RootFolder of the active web, the value for the top
    'margin, and the value of the left margin are all passed to the
    'ChangeMargins procedure.
    ChangeMargins ActiveWeb.RootFolder, TopMargin, LeftMargin
    
    'Display a message box informing user that we're done.
    MsgBox "Page margin settings complete.", vbInformation + vbOKOnly
    
End Sub


Sub ChangeMargins(myFolder As WebFolder, Top As String, Left As String)    

'///////////////////////////////////////////////////////////////////////// 
'//  This procedure takes the WebFolder object, the value for the top
'//  margin, and the value for the left margin and applies the margin
'//  to each page in the folder referenced by the myFolder variable.
'///////////////////////////////////////////////////////////////////////// 
    
    'Set up variables
    Dim myFile As WebFile
    Dim mySubFolder As WebFolder
    Dim myPageWindow As PageWindow
    Dim myDocument As FPHTMLDocument
    Dim myBodyTag As IHTMLElement
    
    'This For loop will traverse through all of the files in the folder
    'represented by the myFolder variable passed to the procedure.
    For Each myFile In myFolder.Files
    
        'Use an If...Then to determine if the file is an HTML or ASP file.
        'We only want to modify these file types. Add your own file types
        'as necessary.
        If LCase(myFile.Extension) = "htm" Or _
          LCase(myFile.Extension) = "html" Or _
          LCase(myFile.Extension) = "asp" Then
            
            'Must be in Normal view to add HTML
            Set myPageWindow = ActiveWebWindow.PageWindows.Add(myFile.Url)
            myPageWindow.ViewMode = fpPageViewNormal
            
            'Set a reference to the current document
            Set myDocument = myPageWindow.Document
            
            'Set a reference to the body tag for the document
            Set myBodyTag = myDocument.all.tags("body").Item(0)
            
            'Now set the margin attributes for the body tag
            'We used attributes for the tag that will work in both
            'Microsoft Internet Explorer and 
            'NetscapeNavigator/Communicator
            
            'Microsoft Internet Explorer tags
            myBodyTag.setAttribute "topmargin", Top
            myBodyTag.setAttribute "leftmargin", Left
            
            'Netscape Navigator/Communicator tags
            myBodyTag.setAttribute "marginheight", Top
            myBodyTag.setAttribute "marginwidth", Left
            
            'Save and close the page
            'The "True" argument passed here forces a save.
            myPageWindow.Close True
            
        End If
        
    Next myFile

    'Loop through all of the subfolders in the web
    For Each mySubFolder In myFolder.Folders
    
        'Call the ChangeMargins procedure and pass each subfolder to it.
        'This is called a recursive procedure.
        'See Q237672 for more information about recursive procedures.
        ChangeMargins mySubFolder, Top, Left
        
    Next mySubFolder

End Sub
				

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:KB272019