![]() Note that you can run the code multiple times without error. Note The error occurs because the code refers to the ActiveDocument Section one's Range object without preceding the call with the oWord object variable. No error occurs.Ĭlick the CommandButton again and note that you receive the error. PageSetup.LeftMargin = oWord.InchesToPoints(1.25) Stop the project and change the following line: Note The error occurs because the code refers to the InchesToPoints Method without preceding the call with the oWord object variable. However, a reference to Word has been created and has not been released.Ĭlick the CommandButton again and note that you receive the error previously described. On the Run menu, click Start or press the F5 key to start the program.Ĭlick the CommandButton. Set oRange = ActiveDocument.Sections(1).Range ' This example inserts text at the end of section one. PageSetup.LeftMargin = InchesToPoints(1.25) MsgBox "Document open", vbMsgBoxSetForeground Set oWord = CreateObject("Word.Application") Form1 is created by default.Ĭlick References from the Project menu, and then click one of the following options:įor Office Word 2007, click Microsoft Word 12.0 Object Libraryįor Word 2003, click Microsoft Word 11.0 Object Libraryįor Word 2003, click Microsoft Word 10.0 Object Libraryįor Word 2000, click Microsoft Word 9.0 Object Library.įor Word 97, click Microsoft Word 8.0 Object Library.Ĭopy the following code to the Code Window of Form1: Start a new Standard EXE project in Visual Basic. ![]() The following steps illustrate how to reproduce this problem, and how to correct it. When running the automation code again, calls to this hidden object variable will fail with the aforementioned error. If Word is shutdown, or if the declared object variable is released, the hidden global variable will now reference an invalid (destroyed) object. If you do not, Visual Basic uses a hidden global variable reference which it sets to the currently running instance. When you write code to use a Word object, method, or property, you should always precede the call with the appropriate object variable. Other object variables can then be set to refer to a Selection, a Range, or other objects in the Word object model. To automate Word, you establish an object variable that usually refers to the Word Application or Document object. Modify the code so that each call to a Word object, method, or property is qualified with the appropriate object variable. This errant reference interferes with automation code when the code is run more than once. Visual Basic does not release this reference until you end the program. ![]() Visual Basic has established a reference to Word due to a line of code that calls a Word object, method, or property without qualifying it with a Word object variable. Run-time error '462': The remote server machine does not exist or is unavailable Cause
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |