Symptoms
When you run Microsoft Visual Basic code that uses Automation to control Microsoft Word, you may receive one of the following error messages:
Error message 1
Run-time error ‘-2147023174’ (800706ba)
Automation error
Error message 2
Run-time error ‘462’: The remote server machine does not exist or is unavailable
Cause
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. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.
Resolution
Modify the code so that each call to a Word object, method, or property is qualified with the appropriate object variable.
Status
This behavior is by design.
More Information
To automate Word, you establish an object variable that usually refers to the Word Application or Document object. Other object variables can then be set to refer to a Selection, a Range, or other objects in the Word object model. When you write code to use a Word object, method, or property, you should always precede the call with the appropriate object variable. If you do not, Visual Basic uses a hidden global variable reference which it sets to the currently running instance. If Word is shutdown, or if the declared object variable is released, the hidden global variable will now reference an invalid (destroyed) object. When running the automation code again, calls to this hidden object variable will fail with the aforementioned error.
The following steps illustrate how to reproduce this problem, and how to correct it.
Steps to Reproduce Behavior
-
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
-
Click References from the Project menu, and then click one of the following options:
-
For Office Word 2007, click Microsoft Word 12.0 Object Library
-
For Word 2003, click Microsoft Word 11.0 Object Library
-
For Word 2003, click Microsoft Word 10.0 Object Library
-
For Word 2000, click Microsoft Word 9.0 Object Library.
-
For Word 97, click Microsoft Word 8.0 Object Library.
-
-
Place a CommandButton on Form1.
-
Copy the following code to the Code Window of Form1:
Option Explicit
Private Sub Command1_Click()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange as Word.RangeSet oWord = CreateObject("Word.Application")
With oWord
.Visible = True
.Activate
.WindowState = wdWindowStateNormal
End WithSet oDoc = oWord.Documents.Add
MsgBox "Document open", vbMsgBoxSetForeground
With oDoc
.PageSetup.LeftMargin = InchesToPoints(1.25)
End With' This example inserts text at the end of section one.
Set oRange = ActiveDocument.Sections(1).Range
With oRange
.MoveEnd Unit:=wdCharacter, Count:= -1
.Collapse Direction:=wdCollapseEnd
.InsertParagraphAfter
.InsertAfter "End of section."
End WithWith oDoc
.Saved = True
End WithSet oRange = Nothing
Set oDoc = Nothing
oWord.Quit
Set oWord = Nothing
End Sub -
On the Run menu, click Start or press the F5 key to start the program.
-
Click the CommandButton. No error occurs. However, a reference to Word has been created and has not been released.
-
Click the CommandButton again and note that you receive the error previously described.
Note The error occurs because the code refers to the InchesToPoints Method without preceding the call with the oWord object variable.
-
Stop the project and change the following line:
.PageSetup.LeftMargin = InchesToPoints(1.25)
.PageSetup.LeftMargin = oWord.InchesToPoints(1.25)
-
Run the program again. Then, click the CommandButton. No error occurs.
-
Click the CommandButton again and note that you receive the 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.
-
Stop the project and change the following line:
Set oRange = ActiveDocument.Sections(1).Range
Set oRange = oWord.ActiveDocument.Sections(1).Range
-
Run the program again. Note that you can run the code multiple times without error.
When building a Visual Basic project automating Word, if your project has a reference to the Microsoft Word Object Library, sample code for the objects, methods, and properties of the Word Object Model is available from the Word Help file. When the cursor is over a key word in your code, you will see any applicable Help text by pressing the F1 key.
The sample code in the Help topic will be the Microsoft Word Visual Basic for Applications code. It will not show the object references that your Visual Basic code requires. You will need to add the qualifiers as appropriate.
References
For additional information, please see the following articles in the Microsoft Knowledge Base:
178510 PRB: Excel Automation Method of Object ‘_Global’Failed
167223 Microsoft Office 97 Automation Help File Available
For additional information about the Automation of Office applications, click the article number below to view the article in the Microsoft Knowledge Base:
222101 HOWTO: Find and Use Office Object Model Documentation
Need more help?
This article features error number Code 462, commonly known as The remote server machine does not exist or is unavailable described as The CreateObject function requires a valid server.
About Runtime Code 462
Runtime Code 462 happens when Windows fails or crashes whilst it’s running, hence its name. It doesn’t necessarily mean that the code was corrupt in some way, but just that it did not work during its run-time. This kind of error will appear as an annoying notification on your screen unless handled and corrected. Here are symptoms, causes and ways to troubleshoot the problem.
Definitions (Beta)
Here we list some definitions for the words contained in your error, in an attempt to help you understand your problem. This is a work in progress, so sometimes we might define the word incorrectly, so feel free to skip this section!
- Createobject — The CreateObject function is used to instantiate COM objects.
- Function — A function also called a procedure, method, subroutine, or routine is a portion of code intended to carry out a single, specific task
- Remote server — remote-server is a machine used for data processing which is accessed via a network
- Server — A server is a running instance of a software application capable of accepting requests from a client and giving responses accordingly.
Symptoms of Code 462 — The remote server machine does not exist or is unavailable
Runtime errors happen without warning. The error message can come up the screen anytime Windows is run. In fact, the error message or some other dialogue box can come up again and again if not addressed early on.
There may be instances of files deletion or new files appearing. Though this symptom is largely due to virus infection, it can be attributed as a symptom for runtime error, as virus infection is one of the causes for runtime error. User may also experience a sudden drop in internet connection speed, yet again, this is not always the case.
(For illustrative purposes only)
Causes of The remote server machine does not exist or is unavailable — Code 462
During software design, programmers code anticipating the occurrence of errors. However, there are no perfect designs, as errors can be expected even with the best program design. Glitches can happen during runtime if a certain error is not experienced and addressed during design and testing.
Runtime errors are generally caused by incompatible programs running at the same time. It may also occur because of memory problem, a bad graphics driver or virus infection. Whatever the case may be, the problem must be resolved immediately to avoid further problems. Here are ways to remedy the error.
Repair Methods
Runtime errors may be annoying and persistent, but it is not totally hopeless, repairs are available. Here are ways to do it.
If a repair method works for you, please click the upvote button to the left of the answer, this will let other users know which repair method is currently working the best.
Please note: Neither ErrorVault.com nor it’s writers claim responsibility for the results of the actions taken from employing any of the repair methods listed on this page — you complete these steps at your own risk.
Method 2 — Update / Reinstall Conflicting Programs
Using Control Panel
- For Windows 7, click the Start Button, then click Control panel, then Uninstall a program
- For Windows 8, click the Start Button, then scroll down and click More Settings, then click Control panel > Uninstall a program.
- For Windows 10, just type Control Panel on the search box and click the result, then click Uninstall a program
- Once inside Programs and Features, click the problem program and click Update or Uninstall.
- If you chose to update, then you will just need to follow the prompt to complete the process, however if you chose to Uninstall, you will follow the prompt to uninstall and then re-download or use the application’s installation disk to reinstall the program.
Using Other Methods
- For Windows 7, you may find the list of all installed programs when you click Start and scroll your mouse over the list that appear on the tab. You may see on that list utility for uninstalling the program. You may go ahead and uninstall using utilities available in this tab.
- For Windows 10, you may click Start, then Settings, then choose Apps.
- Scroll down to see the list of Apps and features installed in your computer.
- Click the Program which is causing the runtime error, then you may choose to uninstall or click Advanced options to reset the application.
Method 1 — Close Conflicting Programs
When you get a runtime error, keep in mind that it is happening due to programs that are conflicting with each other. The first thing you can do to resolve the problem is to stop these conflicting programs.
- Open Task Manager by clicking Ctrl-Alt-Del at the same time. This will let you see the list of programs currently running.
- Go to the Processes tab and stop the programs one by one by highlighting each program and clicking the End Process buttom.
- You will need to observe if the error message will reoccur each time you stop a process.
- Once you get to identify which program is causing the error, you may go ahead with the next troubleshooting step, reinstalling the application.
Method 3 — Update your Virus protection program or download and install the latest Windows Update
Virus infection causing runtime error on your computer must immediately be prevented, quarantined or deleted. Make sure you update your virus program and run a thorough scan of the computer or, run Windows update so you can get the latest virus definition and fix.
Method 4 — Re-install Runtime Libraries
You might be getting the error because of an update, like the MS Visual C++ package which might not be installed properly or completely. What you can do then is to uninstall the current package and install a fresh copy.
- Uninstall the package by going to Programs and Features, find and highlight the Microsoft Visual C++ Redistributable Package.
- Click Uninstall on top of the list, and when it is done, reboot your computer.
- Download the latest redistributable package from Microsoft then install it.
Method 5 — Run Disk Cleanup
You might also be experiencing runtime error because of a very low free space on your computer.
- You should consider backing up your files and freeing up space on your hard drive
- You can also clear your cache and reboot your computer
- You can also run Disk Cleanup, open your explorer window and right click your main directory (this is usually C: )
- Click Properties and then click Disk Cleanup
Method 6 — Reinstall Your Graphics Driver
If the error is related to a bad graphics driver, then you may do the following:
- Open your Device Manager, locate the graphics driver
- Right click the video card driver then click uninstall, then restart your computer
Method 7 — IE related Runtime Error
If the error you are getting is related to the Internet Explorer, you may do the following:
- Reset your browser.
- For Windows 7, you may click Start, go to Control Panel, then click Internet Options on the left side. Then you can click Advanced tab then click the Reset button.
- For Windows 8 and 10, you may click search and type Internet Options, then go to Advanced tab and click Reset.
- Disable script debugging and error notifications.
- On the same Internet Options window, you may go to Advanced tab and look for Disable script debugging
- Put a check mark on the radio button
- At the same time, uncheck the «Display a Notification about every Script Error» item and then click Apply and OK, then reboot your computer.
If these quick fixes do not work, you can always backup files and run repair reinstall on your computer. However, you can do that later when the solutions listed here did not do the job.
Other languages:
Wie beheben Fehler 462 (Der Remote-Server-Rechner existiert nicht oder ist nicht verfügbar) — Die CreateObject-Funktion erfordert einen gültigen Server.
Come fissare Errore 462 (La macchina del server remoto non esiste o non è disponibile) — La funzione CreateObject richiede un server valido.
Hoe maak je Fout 462 (De externe servermachine bestaat niet of is niet beschikbaar) — Voor de functie CreateObject is een geldige server vereist.
Comment réparer Erreur 462 (La machine serveur distante n’existe pas ou n’est pas disponible) — La fonction CreateObject requiert un serveur valide.
어떻게 고치는 지 오류 462 (원격 서버 시스템이 존재하지 않거나 사용할 수 없습니다.) — CreateObject 함수에는 유효한 서버가 필요합니다.
Como corrigir o Erro 462 (A máquina do servidor remoto não existe ou não está disponível) — A função CreateObject requer um servidor válido.
Hur man åtgärdar Fel 462 (Fjärrservermaskinen finns inte eller är inte tillgänglig) — CreateObject -funktionen kräver en giltig server.
Как исправить Ошибка 462 (Удаленный серверный компьютер не существует или недоступен) — Для функции CreateObject требуется действующий сервер.
Jak naprawić Błąd 462 (Zdalny serwer nie istnieje lub jest niedostępny) — Funkcja CreateObject wymaga prawidłowego serwera.
Cómo arreglar Error 462 (La máquina del servidor remoto no existe o no está disponible) — La función CreateObject requiere un servidor válido.
About The Author: Phil Hart has been a Microsoft Community Contributor since 2010. With a current point score over 100,000, they’ve contributed more than 3000 answers in the Microsoft Support forums and have created almost 200 new help articles in the Technet Wiki.
Follow Us:
Last Updated:
21/12/22 11:32 : A Windows 10 user voted that repair method 2 worked for them.
This repair tool can fix common computer problems such as blue screens, crashes and freezes, missing DLL files, as well as repair malware/virus damage and more by replacing damaged and missing system files.
STEP 1:
Click Here to Download and install the Windows repair tool.
STEP 2:
Click on Start Scan and let it analyze your device.
STEP 3:
Click on Repair All to fix all of the issues it detected.
DOWNLOAD NOW
Compatibility
Requirements
1 Ghz CPU, 512 MB RAM, 40 GB HDD
This download offers unlimited scans of your Windows PC for free. Full system repairs start at $19.95.
Article ID: ACX011415EN
Applies To: Windows 10, Windows 8.1, Windows 7, Windows Vista, Windows XP, Windows 2000
Speed Up Tip #20
Cleaning out the Windows XP Prefetch Folder:
Prefetch is a useful and unique technique utilized in Windows XP. However, it can accumulate obsolete and rarely used links over time which can significantly slow down your computer. Just open C(system drive):/windows/prefetch, delete all files and reboot.
Click Here for another way to speed up your Windows PC
Microsoft & Windows® logos are registered trademarks of Microsoft. Disclaimer: ErrorVault.com is not affiliated with Microsoft, nor does it claim such affiliation. This page may contain definitions from https://stackoverflow.com/tags under the CC-BY-SA license. The information on this page is provided for informational purposes only. © Copyright 2018
First problem : Run-time error ‘462’ : The remote server machine does not exist or is unavailable.
The issue here is the use of :
- Late Biding :
Dim Smthg As Object
or - Implicit references :
Dim Smthg As Range
instead of
Dim Smthg As Excel.Range
orDim Smthg As Word.Range
So you need to fully qualified all the variables that you set (I’ve done that in your code)
Second problem
You work with multiple instances of Word and you only need one to handle multiple documents.
So instead of creating a new one each time with :
Set WordApp = CreateObject("Word.Application")
You can get an open instance (if there is one) or create one with that code :
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number > 0 Then Set WordApp = CreateObject("Word.Application")
On Error GoTo 0
And once you’ve put this at the start of your proc, you can use this instance until the end of the proc and before the end, quit it to avoid having multiple instances running.
Here is your code reviewed and cleaned, take a look :
Sub Docs()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
' Control if folder exists, if not create folder
If Len(Dir("F:documents" & Year(Date), vbDirectory)) = 0 Then MkDir "F:documents" & Year(Date)
' Get or Create a Word Instance
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number > 0 Then Set WordApp = CreateObject("Word.Application")
On Error GoTo 0
Workbooks("exampleworkbook.xlsm").Sheets("examplesheet").Range("A1:C33").Copy
With WordApp
.Visible = True
.Activate
Set WordDoc = .Documents.Add
.Selection.PasteSpecial Link:=False, DataType:=wdPasteRTF, _
Placement:=wdInLine, DisplayAsIcon:=False
End With
With Application
.Wait (Now + TimeValue("0:00:02"))
.CutCopyMode = False
End With
With WordDoc
.PageSetup.TopMargin = WordApp.CentimetersToPoints(1.4)
.PageSetup.LeftMargin = WordApp.CentimetersToPoints(1.5)
.PageSetup.BottomMargin = WordApp.CentimetersToPoints(1.5)
.SaveAs "F:documents" & Year(Date) & "examplename " & Format(Now, "YYYYMMDD") & ".docx"
.Close
End With
' export sheet 2 to Word
Workbooks("exampleworkbook.xlsm").Sheets("examplesheet2").Range("A1:C33").Copy
Set WordDoc = WordApp.Documents.Add
WordApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteRTF, _
Placement:=wdInLine, DisplayAsIcon:=False
Application.Wait (Now + TimeValue("0:00:02"))
With WordDoc
.PageSetup.LeftMargin = WordApp.CentimetersToPoints(1.5)
.PageSetup.TopMargin = WordApp.CentimetersToPoints(1.4)
.PageSetup.BottomMargin = WordApp.CentimetersToPoints(1.5)
.SaveAs "F:files" & Year(Date) & "name" & Format(Now, "YYYYMMDD") & ".docx"
.Close
End With
Application.CutCopyMode = False
WordApp.Quit
Set WordDoc = Nothing
Set WordApp = Nothing
' Variables Outlook
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
Dim rngTo As Excel.Range
Dim rngCc As Excel.Range
Dim rngSubject As Excel.Range
Dim rngBody As Excel.Range
Dim rngAttach1 As Excel.Range
Dim rngAttach2 As Excel.Range
Dim numSend As Integer
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set objOutlook = CreateObject("Outlook.Application")
On Error GoTo 0
Set objMail = objOutlook.CreateItem(0)
' Outlook
On Error GoTo handleError
With Sheets("Mail")
Set rngTo = .Range("B11")
Set rngCc = .Range("B12")
Set rngSubject = .Range("B13")
Set rngBody = .Range("B14")
Set rngAttach1 = .Range("B15")
Set rngAttach2 = .Range("B16")
End With
With objMail
.To = rngTo.Value
.Subject = rngSubject.Value
.CC = rngCc.Value
'.Body = rngBody.Value
.Body = "Hi," & _
vbNewLine & vbNewLine & _
rngBody.Value & _
vbNewLine & vbNewLine & _
"Kind regards,"
.Attachments.Add rngAttach1.Value
.Attachments.Add rngAttach2.Value
.Display
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys "%s"
' .Send ' Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
numSend = numSend + 1
GoTo skipError
handleError:
numErr = numErr + 1
oFile.WriteLine "*** ERROR *** Email for account" & broker & " not sent. Error: " & Err.Number & " " & Err.Description
skipError:
On Error GoTo 0
MsgBox "Sent emails: " & numSend & vbNewLine & "Number of errors: " & numErr, vbOKOnly + vbInformation, "Operation finished"
GoTo endProgram
cancelProgram:
MsgBox "No mails were sent.", vbOKOnly + vbExclamation, "Operation cancelled"
endProgram:
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
Set rngAttach1 = Nothing
Set rngAttach2 = Nothing
End Sub
Error Number: | Runtime Error 462 | |
Error Name: | The remote server machine does not exist or is unavailable | |
Error Description: | The CreateObject function requires a valid server. | |
Developer: | Microsoft Corporation | |
Software: | Windows Operating System | |
Applies to: | Windows XP, Vista, 7, 8, 10, 11 |
The remote server machine does not exist or is unavailable Definition
The remote server machine does not exist or is unavailable is a standard sort of runtime error. Programmers work through different levels of debugging in attempt to make sure that Windows Operating System is as close to error-free as possible. Although these preventive actions are taken, at times errors like error 462 will be missed.
In the release of the latest version of Windows Operating System, an error could be encountered that reads, «The CreateObject function requires a valid server.». If error 462 occurs, developers will be told about that issue through error notifications that are built-in Windows Operating System. Microsoft Corporation can then fix these errors in the source code and prepare an update for download. If there is notification for a Windows Operating System update, it can be a solution for fixing issues like error 462 and additional issues discovered.
What Generates Runtime Error 462?
Execution faults at the startup of Windows Operating System is when you’re most likely to run into The remote server machine does not exist or is unavailable. The following three most significant causes of error 462 runtime errors include:
Error 462 Crash — Error 462 will stop the machine from performing a regular program operation. This emerges when Windows Operating System fails to respond to input properly, or does not know what output is required in return.
The remote server machine does not exist or is unavailable Memory Leak — This type of memory leak causes Windows Operating System to keep using increasing amounts of memory, bringing down the total system performance. Possible sparks include a deallocation failure that happened in a non-C++ program, when corrupted assembly code improperly executes an infinite loop.
Error 462 Logic Error — A logic error triggers the wrong output even when the user has given valid input data. Microsoft Corporation’s faulty source code can lead to these issues with input handling.
These The remote server machine does not exist or is unavailable problems are generally caused by Windows Operating System-related file corruption, or in some cases, if the file has been accidentally or maliciously removed. Obtaining a new, uninfected copy of your Microsoft Corporation file will usually resolve the problem. As a supplemental troubleshooting step, we highly recommend cleaning up any invalid file path and Microsoft Corporation file extension references that could contribute to creating these The remote server machine does not exist or is unavailable error messages.
Typical The remote server machine does not exist or is unavailable Errors
Encountered The remote server machine does not exist or is unavailable Problems with Windows Operating System Include:
- «The remote server machine does not exist or is unavailable Application Error.»
- «The remote server machine does not exist or is unavailable is not a valid Win32 application.»
- «Sorry, The remote server machine does not exist or is unavailable encountered a problem.»
- «Can’t locate The remote server machine does not exist or is unavailable»
- «The remote server machine does not exist or is unavailable is missing.»
- «Start-up error in application: The remote server machine does not exist or is unavailable.»
- «The remote server machine does not exist or is unavailable is not running.»
- «The remote server machine does not exist or is unavailable failure.»
- «Software Path Fault: The remote server machine does not exist or is unavailable.»
The remote server machine does not exist or is unavailable EXE errors happen during Windows Operating System installation, while running The remote server machine does not exist or is unavailable-related applications (Windows Operating System), during startup or shutdown, or during installation of Windows OS. Documenting The remote server machine does not exist or is unavailable problem occasions in Windows Operating System is key to determine cause of the Windows problems, and reporting them to Microsoft Corporation.
Origins of The remote server machine does not exist or is unavailable Troubles
Windows Operating System and The remote server machine does not exist or is unavailable issues come from missing or corrupt files, Windows registry invalid entries, and malware infections.
More specifically, these The remote server machine does not exist or is unavailable errors can be caused by:
- Invalid The remote server machine does not exist or is unavailable or corrupted registry key.
- Virus or malware corrupting The remote server machine does not exist or is unavailable.
- A different program (not related with Windows Operating System) deleted The remote server machine does not exist or is unavailable maliciously or by mistake.
- Another software in conflict with Windows Operating System, The remote server machine does not exist or is unavailable, or shared references.
- Corrupted installation or download of Windows Operating System (The remote server machine does not exist or is unavailable).
Product by Solvusoft
Download Now
WinThruster 2022 — Scan your PC for computer errors.
Compatible with Windows 11, 10, 8, 7, Vista, XP and 2000
Optional Offer for WinThruster by Solvusoft | EULA | Privacy Policy | Terms | Uninstall
Все доброй ночи!
Очень извиняюсь, что касаюсь избитой темы (наверное), но что-то я не смог найти ответа в таком форуме, хотя регулярно пользуюсь подсказками пользователей. До сей поры хватало.
Суть вот в чем:
Я хочу из существующей таблицы Excel выдернуть отсортированные значения и вставить их в Word. Казалось бы, что может быть проще:
Sub Import2()
‘
‘
‘
Mesyats = UserForm1.ComboBox1.Value
‘Mesyats = «Ноябрь»
Dim iLastRow As Long
Excel.Sheets(«123»).Select
iLastRow = Cells(Rows.Count, 1).End(xlUp).Row
Excel.ActiveSheet.ListObjects(«Таблица 3»).Range.AutoFilter Field:=1, Criteria1:=Mesyats
Excel.Range(«B3:D» + Right((Str(iLastRow)), (Len(Str(iLastRow) — 1)))).Select
Excel.Selection.Copy
Excel.Sheets(«123»).Select
On Error GoTo ErrStartWord
Dim Wda As Word.Application
Set Wda = GetObject(, «Word.Application»)
Set Wda = Nothing
‘If Tasks.Exists(«Microsoft Word») Then
‘End If
‘Word.Application.Documents.Item
Word.Documents.Open Filename:=»c:OLS ReportsForm 2.docx»
Word.Application.Activate
Word.Selection.StartOf Unit:=wdStory, Extend:=wdMove
Word.Selection.MoveDown Unit:=wdLine, Count:=9
Word.Selection.MoveLeft Unit:=wdCharacter, Count:=17
Word.Selection.Delete Unit:=wdCharacter, Count:=7
Word.Selection.TypeText (Mesyats)
Word.Selection.MoveEnd
Word.Selection.MoveDown Unit:=wdLine, Count:=6
Word.Selection.MoveLeft Unit:=wdCharacter, Count:=1
WordBasic.EditPaste2
‘Word.Application.Dialogs(wdDialogFileSaveAs).Show
‘Word.Documents.Close
ErrStartWord:
If Err.Number = 429 Then ‘ Word не запущен
Dim appWD As Object
Set appWD = CreateObject(«Word.Application»)
appWD.Visible = True
Resume Next
End If
If Err.Number = 0 Then
‘MsgBox «Success!»
Else: MsgBox Err.Description & » » & Err.Number, vblnformation
End If
End Sub
Однако не тут-то было (((
При повторном запуске скрипт срубается на строке «Word.Documents.Open Filename:=»c:OLS ReportsForm 2.docx»»
с сообщением «The remote server machine does not exist or is unavailable 462», как и положено обработчику ошибок в теле сркипта. Надо полностью закрыть Excel и заново в него зайти. Тогда вновь все заработает, на 1 раз :/ Я так думаю, что скрипт по завершению не очищает какие-то переменные, и нужно выйти из Excel.
Очень надо сделать, работа горит. Сижу уже 4-й час, и ничего не могу поделать ((((
И да. Использую Word 2007 и Excel 2007. Как думаете, в 2003 офисе такой проблемы не возникнет? А то будет жаль перставлять из-за этого…..
Все харанее спасибо.
- Remove From My Forums
-
Question
-
Hi
I am using MS Access VBA to send email via OL2010. When below line is executed
for the second time I get a «Run-time error ‘462’: The remote server machine does not exist or is unavailable.” error.Set objOutlook = CreateObject(«Outlook.Application»)
This code worked for OL2003/2007/WinXP. The problem comes on OL2010/Win7. What is wrong and how can I fix it?
Thanks
Regards
Answers
-
Hi,
First, I would consider using set objOL = GetObject(,»Outlook.Application»), and only if objOL is Nothing, use CreateObject.
Now, if CreateObject for Outlook fails on second time, I would consider the following scenario:
1. OL was down
2. You used your code, loaded OL with CreateObject, and ran the code.
3. OL was supposed to go down — but the code did not free OL, and it stuck in-between (probably can be seen in Task Manager)
Now when you try to reload it, Outlook COM Server failes.Could you paste the code you are using?
Moshe
-
Marked as answer by
Friday, May 11, 2012 10:09 AM
-
Marked as answer by
-
please add right after CreateObject following lines:
set session = objOutlook.GetNamespace(«MAPI»)
session.Logon
-
Marked as answer by
Y a h y a
Friday, May 11, 2012 10:09 AM
-
Marked as answer by
Содержание
- You may receive the «Run-time error ‘-2147023174’ (800706ba)» error message or the «Run-time error ‘462’» when you run Visual Basic code that uses Automation to control Word
- Symptoms
- Cause
- Resolution
- Status
- More Information
- Steps to Reproduce Behavior
- References
- You may receive the «Run-time error ‘-2147023174’ (800706ba)» error message or the «Run-time error ‘462’» when you run Visual Basic code that uses Automation to control Word
- Symptoms
- Cause
- Resolution
- Status
- More Information
- Steps to Reproduce Behavior
- References
- Excel automation fails second time code runs
- Symptoms
- Cause
- Resolution
- Status
- More Information
- Steps to reproduce the behavior
- References
- Vba runtime error 462 word
You may receive the «Run-time error ‘-2147023174’ (800706ba)» error message or the «Run-time error ‘462’» when you run Visual Basic code that uses Automation to control Word
Symptoms
When you run Microsoft Visual Basic code that uses Automation to control Microsoft Word, you may receive one of the following error messages:
Error message 1
Run-time error ‘-2147023174’ (800706ba)
Automation error
Error message 2
Run-time error ‘462’: The remote server machine does not exist or is unavailable
Cause
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. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.
Resolution
Modify the code so that each call to a Word object, method, or property is qualified with the appropriate object variable.
Status
This behavior is by design.
More Information
To automate Word, you establish an object variable that usually refers to the Word Application or Document object. Other object variables can then be set to refer to a Selection, a Range, or other objects in the Word object model. When you write code to use a Word object, method, or property, you should always precede the call with the appropriate object variable. If you do not, Visual Basic uses a hidden global variable reference which it sets to the currently running instance. If Word is shutdown, or if the declared object variable is released, the hidden global variable will now reference an invalid (destroyed) object. When running the automation code again, calls to this hidden object variable will fail with the aforementioned error.
The following steps illustrate how to reproduce this problem, and how to correct it.
Steps to Reproduce Behavior
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Click References from the Project menu, and then click one of the following options:
For Office Word 2007, click Microsoft Word 12.0 Object Library
For Word 2003, click Microsoft Word 11.0 Object Library
For Word 2003, click Microsoft Word 10.0 Object Library
For Word 2000, click Microsoft Word 9.0 Object Library.
For Word 97, click Microsoft Word 8.0 Object Library.
Place a CommandButton on Form1.
Copy the following code to the Code Window of Form1:
On the Run menu, click Start or press the F5 key to start the program.
Click the CommandButton. No error occurs. However, a reference to Word has been created and has not been released.
Click the CommandButton again and note that you receive the error previously described.
Note The error occurs because the code refers to the InchesToPoints Method without preceding the call with the oWord object variable.
Stop the project and change the following line:
Run the program again. Then, click the CommandButton. No error occurs.
Click the CommandButton again and note that you receive the 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.
Stop the project and change the following line:
Run the program again. Note that you can run the code multiple times without error.
When building a Visual Basic project automating Word, if your project has a reference to the Microsoft Word Object Library, sample code for the objects, methods, and properties of the Word Object Model is available from the Word Help file. When the cursor is over a key word in your code, you will see any applicable Help text by pressing the F1 key.
The sample code in the Help topic will be the Microsoft Word Visual Basic for Applications code. It will not show the object references that your Visual Basic code requires. You will need to add the qualifiers as appropriate.
References
For additional information, please see the following articles in the Microsoft Knowledge Base:
178510 PRB: Excel Automation Method of Object ‘_Global’Failed
167223 Microsoft Office 97 Automation Help File Available
For additional information about the Automation of Office applications, click the article number below to view the article in the Microsoft Knowledge Base:
222101 HOWTO: Find and Use Office Object Model Documentation
Источник
You may receive the «Run-time error ‘-2147023174’ (800706ba)» error message or the «Run-time error ‘462’» when you run Visual Basic code that uses Automation to control Word
Symptoms
When you run Microsoft Visual Basic code that uses Automation to control Microsoft Word, you may receive one of the following error messages:
Error message 1
Run-time error ‘-2147023174’ (800706ba)
Automation error
Error message 2
Run-time error ‘462’: The remote server machine does not exist or is unavailable
Cause
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. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.
Resolution
Modify the code so that each call to a Word object, method, or property is qualified with the appropriate object variable.
Status
This behavior is by design.
More Information
To automate Word, you establish an object variable that usually refers to the Word Application or Document object. Other object variables can then be set to refer to a Selection, a Range, or other objects in the Word object model. When you write code to use a Word object, method, or property, you should always precede the call with the appropriate object variable. If you do not, Visual Basic uses a hidden global variable reference which it sets to the currently running instance. If Word is shutdown, or if the declared object variable is released, the hidden global variable will now reference an invalid (destroyed) object. When running the automation code again, calls to this hidden object variable will fail with the aforementioned error.
The following steps illustrate how to reproduce this problem, and how to correct it.
Steps to Reproduce Behavior
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
Click References from the Project menu, and then click one of the following options:
For Office Word 2007, click Microsoft Word 12.0 Object Library
For Word 2003, click Microsoft Word 11.0 Object Library
For Word 2003, click Microsoft Word 10.0 Object Library
For Word 2000, click Microsoft Word 9.0 Object Library.
For Word 97, click Microsoft Word 8.0 Object Library.
Place a CommandButton on Form1.
Copy the following code to the Code Window of Form1:
On the Run menu, click Start or press the F5 key to start the program.
Click the CommandButton. No error occurs. However, a reference to Word has been created and has not been released.
Click the CommandButton again and note that you receive the error previously described.
Note The error occurs because the code refers to the InchesToPoints Method without preceding the call with the oWord object variable.
Stop the project and change the following line:
Run the program again. Then, click the CommandButton. No error occurs.
Click the CommandButton again and note that you receive the 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.
Stop the project and change the following line:
Run the program again. Note that you can run the code multiple times without error.
When building a Visual Basic project automating Word, if your project has a reference to the Microsoft Word Object Library, sample code for the objects, methods, and properties of the Word Object Model is available from the Word Help file. When the cursor is over a key word in your code, you will see any applicable Help text by pressing the F1 key.
The sample code in the Help topic will be the Microsoft Word Visual Basic for Applications code. It will not show the object references that your Visual Basic code requires. You will need to add the qualifiers as appropriate.
References
For additional information, please see the following articles in the Microsoft Knowledge Base:
178510 PRB: Excel Automation Method of Object ‘_Global’Failed
167223 Microsoft Office 97 Automation Help File Available
For additional information about the Automation of Office applications, click the article number below to view the article in the Microsoft Knowledge Base:
222101 HOWTO: Find and Use Office Object Model Documentation
Источник
Excel automation fails second time code runs
Symptoms
While running code that uses Automation to control Microsoft Excel, one of the following errors may occur:
In Microsoft Excel 97 and in later versions of Excel, you receive one of the following error message:
Error message 1
Run-time error ‘1004’:
Method ‘ ‘ of object ‘_Global’ failed
Error message 2
Application-defined or object-defined error
In Microsoft Excel 95, you receive one of the following error messages:
Error message 1
Run-time error ‘-2147023174’
OLE Automation error
Error message 2
Run-time error ‘462’:
The remote server machine does not exist or is unavailable.
Cause
Visual Basic has established a reference to Excel because of a line of code that calls an Excel object, method, or property without qualifying the element with an Excel object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than one time.
Resolution
To resolve this problem, modify the code so each call to an Excel object, method, or property is qualified with the appropriate object variable.
Status
This behavior is by design.
More Information
To automate Microsoft Excel, you establish an object variable that usually refers to the Excel Application object or the Excel Workbook object. Other object variables can then be set to refer to a Worksheet, a Range, or other objects in the Microsoft Excel object model. When you write code to use an Excel object, method, or property, you should always precede the call with the appropriate object variable. If you do not, Visual Basic establishes its own reference to Excel. This reference might cause problems when you try to run the automation code multiple times. Note that even if the line of code begins with the object variable, a call may be made to an Excel object, method, or property in the middle of the line of code that is not preceded with an object variable.
The following steps illustrate how to reproduce this issue and how to correct the issue.
Steps to reproduce the behavior
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
On the Project menu, click References, and then check the Object Library for the version of Excel that you intend to automate.
Place a CommandButton control on Form1.
Copy the following code example to the Code Window of Form1.
On the Run menu, click Start, or press F5 to start the program.
Click the CommandButton control. No error occurs. However, a reference to Excel has been created and has not been released.
Click the CommandButton control again. Notice that you receive one of the error messages that are discussed in the «Symptoms» section.
Note The error message occurs because the code refers to the method of the cell without preceding the call with the
xlSheet object variable.
Stop the project and change the following line of code:
Change the line of code to resemble the following line of code.
Run the program again. Notice that you can run the code multiple times without receiving an error message.
References
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
167223 Microsoft Office 97 Automation Help file available
189618 You may receive the «Run-time error ‘-2147023174’ (800706ba)» error message or the «Run-time error ‘462’» when you run Visual Basic code that uses Automation to control Word
Источник
Vba runtime error 462 word
Здесь обсуждаются вопросы по языку Visual Basic 1-6 (а так же по схожим языкам, как, например, PowerBASIC).
Вопросы по Visual Basic .NET (это который входит в состав Visual Studio 2002/2003/2005/2008+, для тех, кто не в курсе) обсуждаются в разделе .NET.
Обратите внимание:
1. Прежде чем начать новую тему или отправить сообщение, убедитесь, что Вы не нарушаете правил форума!
2. Обязательно воспользуйтесь поиском. Возможно, Ваш вопрос уже обсуждали. Полезные ссылки приведены ниже.
3. Темы с просьбой выполнить какую-либо работу за автора в этом разделе не обсуждаются. Студенты, вам сюда: ПОМОЩЬ СТУДЕНТАМ !
4. Используйте теги [ code=vba ] . текст программы. [ /code ] для выделения текста программы подсветкой.
5. Помните, здесь телепатов нет. Формулируйте свой вопрос максимально грамотно и чётко: Как правильно задавать вопросы
6. Запрещено отвечать в темы месячной (и более) давности, без веских на то причин.
Полезные ссылки:
FAQ Сайта
FAQ Раздела
Кладовка
Наши Исходники
API-Guide
Поиск по Разделу
MSDN Library Online
Google
Ваше мнение о модераторах: SCINER, B.V.
Источник