Microsoft KB Archive/272019

= FP2000: How to Set Page Margins by Using VBA =

Article ID: 272019

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft FrontPage 2000 Standard Edition

-



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 &quot;0&quot; is specified TopMargin = InputBox(&quot;Please specify the top margin in pixels:&quot;,, 0) LeftMargin = InputBox(&quot;Please specify the left margin in pixels:&quot;,, 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 &quot;Page margin settings complete.&quot;, 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) = &quot;htm&quot; Or _ LCase(myFile.Extension) = &quot;html&quot; Or _ LCase(myFile.Extension) = &quot;asp&quot; 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(&quot;body&quot;).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 &quot;topmargin&quot;, Top myBodyTag.setAttribute &quot;leftmargin&quot;, Left 'Netscape Navigator/Communicator tags myBodyTag.setAttribute &quot;marginheight&quot;, Top myBodyTag.setAttribute &quot;marginwidth&quot;, Left 'Save and close the page 'The &quot;True&quot; 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

Additional query words: fp2k VBE VB

Keywords: KB272019

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.