WD98: Changing PaperSize Using VBA Causes Run-time Error (177098)
The information in this article applies to:
- Microsoft Word 98 Macintosh Edition
This article was previously published under Q177098 SYMPTOMS
When you try to set the page size of a document using the PaperSize
property in Microsoft Visual Basic for Applications code, you receive the
following error message:
Run-time error '5861':
'<box>
where <box> represents a graphical box.
CAUSE
The following sample code causes the error:
ActiveDocument.Sections(1).PageSetup.PaperSize = wdPaperLetter
WORKAROUNDMicrosoft 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 work around this problem, use one of the following methods:
Method 1: Record Setting the Page Size
Record setting the page size and incorporate the results into your macro.
To record a macro:
- On the Tools menu, point to Macro, and then click Record New Macro.
- In the Macro name box, type a name for the macro.
- In the Store Macro In box, click the template or document in which you
want to store the macro.
- In the Description box, type a description for the macro.
- If you do not want to assign the macro to a toolbar, a menu, or shortcut
keys, click OK to begin recording the macro.
Method 2: Use the Following Sample Visual Basic Procedure
The following sample Visual Basic code sets the page size for all pages
within the first section of a document to Legal. If your document contains
only one section, this example will work as shown.
Sub SetPageSize()
' If there are no open documents, exit this procedure.
If Application.Documents.Count = 0 Then Exit Sub
' Set Page size for the first section.
With ActiveDocument.Sections(1).PageSetup
' Set page orientation to portrait.
.Orientation = wdOrientPortrait
' Set page size to Legal.
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(14)
End With
End Sub
Note: You will want to set margins or other attributes applicable to the
page size. In this case, using Method 1 (found earlier in this article)
would provide a much simpler approach to work around this problem.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. We are researching this problem
and will post new information here in the Microsoft Knowledge Base as it
becomes available.
REFERENCES
For more information about the PageSetup property, click the Office
Assistant in the Visual Basic Editor, type "PageSetup," click Search, and
then click to view "PageSetup Property."
NOTE: If the Assistant is hidden, click the Office Assistant button on the
Standard toolbar. If Microsoft Word Help is not installed on your computer,
please see the following article in the Microsoft Knowledge Base:
120802 Office: How to Add/Remove a Single Office Program or Component
For more information about getting help with Visual Basic for Applications,
please see the following article in the Microsoft Knowledge Base:
163435 VBA: Programming Resources for Visual Basic for Applications
Modification Type: | Major | Last Reviewed: | 6/17/2005 |
---|
Keywords: | kbbug kbcode kbProgramming KB177098 |
---|
|