Error 5981 vbscript

I've created macro in excel 2013 where I point some data from excel to Word (via word template). in excel 2013 everything works perfectly, but now I have to run this excel also in older company PC ...

I’ve created macro in excel 2013 where I point some data from excel to Word (via word template).
in excel 2013 everything works perfectly, but now I have to run this excel also in older company PC where is installed only M$ Office 2010/win7 — fresh installation.

Set objDoc = objWord.Documents.Add(Template:=ThisWorkbook.Sheets("Data").Range("O1").Value & ThisWorkbook.Sheets("Data").Range("G2").Value)

in this excel 2010 I get run-time error 5981 (application-defined or object-defined error).

in cell «O1» is file folder where are this excel + word templates saved
cell «G2» contain info which template should be used (according to dropdown selection).

update: I’ve checked this on other PC with office 2010 and it works. Probably some add-in/library is not working correctly, but idk how to check it.

asked Jul 21, 2015 at 10:31

tryzhas's user avatar

1

Error 5981 seems to have two descriptions attached to it (why?):

  1. Could not open macro storage
  2. Application-defined or object-defined error

Since I got the second description I can only comment on that one, although «Could not open macro storage» seems to suggest that there is something wrong with (the macro’s in) the Word file itself.

In my situation the cause of error 5981 was that the Word-template was not a trusted document.
When opening the Word-template manually, it was opened in protected view. When opening the template automatically via VBA this apparently results in an error 5981.

answered Sep 16, 2016 at 12:01

Mill's user avatar

MillMill

1126 bronze badges

The error is because when you open the word template the view is protected.
Solution: disable protected view in microsotf word
Go to options, trusted center, protected view disable

answered Jun 7, 2017 at 23:48

walter's user avatar

Внимание, откроется в новом окне.
PDFПечать

Проблема характерна для старших версий MS Office (2010 и выше).

При создании документов (протоколов или сводных отчетов) возможно возникновение ошибки «5981 — Не удается открыть банк макросов», как показано на рисунке.

Дополнительно данная ошибка может сопровождаться еще одной ошибкой (Error «5460 — Ошибка файла»), которая также возникает при создании новых документов.

Причиной данных ошибок является блокировка шаблонов программы из-за особого режима безопасности MS Word (блокируются файлы, полученные  из Internet, из внешнего источника или из сетевой папки).

Проблема характеризуется последующими сообщениями над документом, который подвергся блокировке, как показано на рисунке.

Можно применить изменения к конкретному шаблону, используя кнопки «Разрешить редактирование» или «Включить содержимое», но лучше это сделать для всех используемых шаблонов, как описано ниже.

Известны 2 случая, которые приводят к блокировкам со стороны MS Word.

1 Случай. Блокируются шаблоны из стандартной папки templates другого ПК и воспринимаются MS Word как файлы из внешнего источника.

В данной ситуации необходимо добавить папку с шаблонами в надежные расположения MS Word через меню «Файл — Параметры», как показано на рисунке.

Путь к папке с шаблонами по умолчанию: C:ProgramDataattest55.1templates

Папка с шаблонами по умолчанию находится в папке с настройками пользователя. Где хранятся настройки пользователя дополнительно можно ознакомиться в следующем МАТЕРИАЛЕ.

2 Случай. Для шаблонов настроена отдельная папка templates.

В этом случае выполняются такие же действия, что и для случая 1, но в надежных расположениях уже необходимо прописать путь, который определен пользователем для хранения шаблонов.

How to fix the Runtime Code 5981 Microsoft Word Error 5981

This article features error number Code 5981, commonly known as Microsoft Word Error 5981 described as Error 5981: Microsoft Word has encountered a problem and needs to close. We are sorry for the inconvenience.

About Runtime Code 5981

Runtime Code 5981 happens when Microsoft Word 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!

  • Microsoft word — For programming questions related to Microsoft’s «Word» editor

Symptoms of Code 5981 — Microsoft Word Error 5981

Runtime errors happen without warning. The error message can come up the screen anytime Microsoft Word 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.

Fix Microsoft Word Error 5981 (Error Code 5981)
(For illustrative purposes only)

Causes of Microsoft Word Error 5981 — Code 5981

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 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 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 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:

  1. 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.
  2. 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 5981 (Microsoft Word-Fehler 5981) — Fehler 5981: Microsoft Word hat ein Problem festgestellt und muss geschlossen werden. Wir entschuldigen uns für die Unannehmlichkeiten.
Come fissare Errore 5981 (Errore 5981 di Microsoft Word) — Errore 5981: Microsoft Word ha riscontrato un problema e deve essere chiuso. Ci scusiamo per l’inconveniente.
Hoe maak je Fout 5981 (Microsoft Word-fout 5981) — Fout 5981: Microsoft Word heeft een probleem ondervonden en moet worden afgesloten. Excuses voor het ongemak.
Comment réparer Erreur 5981 (Erreur Microsoft Word 5981) — Erreur 5981 : Microsoft Word a rencontré un problème et doit se fermer. Nous sommes désolés du dérangement.
어떻게 고치는 지 오류 5981 (마이크로소프트 워드 오류 5981) — 오류 5981: Microsoft Word에 문제가 발생해 닫아야 합니다. 불편을 끼쳐드려 죄송합니다.
Como corrigir o Erro 5981 (Erro 5981 do Microsoft Word) — Erro 5981: O Microsoft Word encontrou um problema e precisa fechar. Lamentamos o inconveniente.
Hur man åtgärdar Fel 5981 (Microsoft Word-fel 5981) — Fel 5981: Microsoft Word har stött på ett problem och måste avslutas. Vi är ledsna för besväret.
Как исправить Ошибка 5981 (Ошибка Microsoft Word 5981) — Ошибка 5981: Возникла ошибка в приложении Microsoft Word. Приложение будет закрыто. Приносим свои извинения за неудобства.
Jak naprawić Błąd 5981 (Błąd Microsoft Word 5981) — Błąd 5981: Microsoft Word napotkał problem i musi zostać zamknięty. Przepraszamy za niedogodności.
Cómo arreglar Error 5981 (Error 5981 de Microsoft Word) — Error 5981: Microsoft Word ha detectado un problema y debe cerrarse. Lamentamos las molestias.

The Author 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: Facebook Youtube Twitter

Last Updated:

11/04/22 07:16 : A iPhone user voted that repair method 2 worked for them.

Recommended Repair Tool:

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: ACX08353EN

Applies To: Windows 10, Windows 8.1, Windows 7, Windows Vista, Windows XP, Windows 2000

Speed Up Tip #27

Troubleshooting Slow Right-Click Context Menu:

Slow appearing right-click context menu is a common yet very annoying problem in Windows. Troubleshoot the issue by checking on your third-party extensions, graphics driver and registry keys. Also, check the installed programs on your computer as they would sometimes interfere with the right-click process.

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

  1. Jul 2nd, 2016, 04:38 PM


    #1

    brayshaw36 is offline

    Thread Starter


    New Member


    Resolved [RESOLVED] closing files when error 5981 occrs

    I have word vb code which navigates a directory structure and opens all word files in read only mode for text string content checking. Occasionally a word document fails to open and reports error code 5981. I wish to close the file and continue the run but activedocument.close and documents(myfilename).close have no effect and all such files remain open and have to be closed manually at end of run. Immediately after opening the active document is shown as <Cannot open macro storage.> in the Documents collection.


  2. Jul 2nd, 2016, 06:10 PM


    #2

    Re: closing files when error 5981 occrs

    have you tried application.displayalerts = false?

    what version of word /windows?

    i found this from some other forum

    I found the solution. Right click the docx, select properties then UNBLOCK. It would seem that word puts a block on the file if its downloaded from the internet.

    Last edited by westconn1; Jul 2nd, 2016 at 06:15 PM.

    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete


  3. Jul 2nd, 2016, 07:19 PM


    #3

    Re: closing files when error 5981 occrs

    I assume you have error handling code wrapping your document open routine?

    Burn the land and boil the sea
    You can’t take the sky from me

    ~T


  4. Jul 2nd, 2016, 07:51 PM


    #4

    Re: closing files when error 5981 occrs

    there is methods by code to unblock documents

    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete


  5. Jul 3rd, 2016, 01:07 AM


    #5

    brayshaw36 is offline

    Thread Starter


    New Member


    Re: closing files when error 5981 occrs

    Thanks for the prompt replies. Yes I do set the error trap. I am using Word 2010. I will try display alerts but as I do not get a display when running under VB I don’t understand why this is a fix — but worth a try. Manually unblocking the document is not an option in the middle of a VB controlled run examining several thousand files and finding a handful fail with error 5981. I think that one solution is to open the files in a separate instance of Word but in a thin client environment with 2003 and 2010 versions of word I have a problem on how to code to always obtain a 2010 instance and how to test this code in a variety of different user environments.


  6. Jul 3rd, 2016, 01:50 AM


    #6

    Re: closing files when error 5981 occrs

    i do not know how, by code, to test if the documents are blocked, but it would be possible to unblock all files prior to opening them in word, within the code

    whether the time overhead of doing this would make it unviable i can not say, it may, to some degree at least, depend on the size of the files, if the whole process is being run in background it may not matter at all

    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete


  7. Jul 3rd, 2016, 05:18 PM


    #7

    Re: closing files when error 5981 occrs

    Out of curiosity is your word document format docx?

    Burn the land and boil the sea
    You can’t take the sky from me

    ~T


  8. Jul 5th, 2016, 03:47 PM


    #8

    brayshaw36 is offline

    Thread Starter


    New Member


    Re: closing files when error 5981 occrs

    Docx — I have recoded to open in a separate instance of word and this has overcome the problem — thanks for you help


  • #2

Hi Steve

There are several possible causes of a 5981 error, but the most frequent in
my experience is a broken reference. Your task will be to track down which
of your files has the broken reference.

To do that, do Tools > Templates and Addin-ins and un-load all addins
(global templates) listed in that dialog box.

Now, use File > Open to open each of the .dot files in your startup folder.

Use Alt-F11 to open the VBE. In the project explorer, click on each of your
open files in turn. For each file, do Tools > References. If you find a
broken reference, you’ll need to un-tick that reference, close the dialog
box, re-open Tools > References and set the reference to the correct source.
Then save that file.

The best way to copy macros from one file to another is to use the VBE.
Using the Organizer, you can only copy some things, and only a whole module
at a time. But to work with a file that is loaded as an add-in, you must
first un-load it, and then use File > Open to open it.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word

hello everyone.. pls help!!!

i am getting the above error INTERMITTENTLY when i run the 2 macros that i have created.. i know there is a similar article on this posted long back but that doesn’t seem to resolve my problem… i have also gone thru the below link but all the options suggested don’t seem to apply in my case —

http://support.microsoft.com/support/kb/articles/q162/0/53.asp

let me explain why… the 1st macro converts a doc file to pdf (by creating a postscript file first using a print driver and then creating the pdf from the .ps file using acrodist.exe).. the 2nd macro simply converts the doc file to .prn using a print driver… both macros are executed via toolbar icons and are in the same template file (.dot) which is placed in C:mydocs… also the workgroup template (Word -> Tools -> Options -> File Locations) is pointed to C:mydocs so that the macros come up automatically when the doc is fetched from the repository (all docs are stored on a server)… also the output files (.pdf and .prn) go to a diff server.

now the macros run fine but give the above error occasionally.. the options mentioned in the above link are not helping me since —

— when the doc on which the macro error occurs is closed and again re-fetched from the repository, the macro runs fine… also the error does not occur always.. nor on any specific doc.. so normal.dot and vbe.dll should be supposedly fine (or else the error would happen for all)

— n/w permissions are all correct for the same reason above

— RAM is 255MB and HDD space is 20GB.. no other applications are open.

pls let me know if i have missed anything or got something wrong..

pls advise.

thanks in advance.
aakash.

Icon Ex Error Number: Error 5981
Error Name: Microsoft Word Error 5981
Error Description: Error 5981: Microsoft Word has encountered a problem and needs to close. We are sorry for the inconvenience.
Developer: Microsoft Corporation
Software: Microsoft Word
Applies to: Windows XP, Vista, 7, 8, 10, 11

Microsoft Word Error 5981 Assessment

Microsoft Word Error 5981 is generally referred to as a form of «runtime error». To make sure that the functionality and operations are all working in a usable condition, software developers like Microsoft Corporation do debugging before software releases. Sadly, some critical issues such as error 5981 can often be overlooked.

Error 5981 is also displayed as «Microsoft Word Error 5981». It is a common error that might occur after installation of the software. If Microsoft Word Error 5981 occurs, developers will be told about that issue though error reporting built-into the application. Microsoft Corporation will then have the knowledge to investigate how and where to fix the issue. Thus, when your PC carries out updates like this, it’s typically to correct problems of error 5981 and other bugs inside Microsoft Word.

How Runtime Error 5981 Triggers, and What Is It?

The first time you might experience a Microsoft Word runtime error is usually with Microsoft Word Error 5981 at program startup. The following three most significant causes of error 5981 runtime errors include:

Error 5981 Crash — This is a typical «Microsoft Word Error 5981» error that leads to total program termination. This occurs a lot when the product (Microsoft Word) or computer is unable to handle the unique input data.

Microsoft Word Error 5981 Memory Leak — This type of memory leak causes Microsoft Word to keep using increasing amounts of memory, bringing down the total system performance. A potential factor of the error is Microsoft Corporation’s code since the error prevents the program from ending.

Error 5981 Logic Error — A «logic error» is said to be generated when software receives the correct input but generates incorrect output. Usual causes of this problem are due to faults in data handling.

These Microsoft Word Error 5981 problems are generally caused by Microsoft Word-related file corruption, or in some cases, if the file has been accidentally or maliciously removed. Although annoying, these issues can usually be easily remedied through replacing the problem Microsoft Corporation file. Additionally, some Microsoft Word Error 5981 errors can be due to incorrect registry references, so we recommend conducting a registry scan to clean up any invalid entries.

Microsoft Word Error 5981 Errors

Microsoft Word Complications with Microsoft Word Error 5981 Comprise Of:

  • «Microsoft Word Error 5981 Error.»
  • «Invalid Win32 Program: Microsoft Word Error 5981»
  • «Microsoft Word Error 5981 needs to close.»
  • «Microsoft Word Error 5981 can’t be located.»
  • «Microsoft Word Error 5981 not found.»
  • «Problem starting application: Microsoft Word Error 5981.»
  • «Microsoft Word Error 5981 not executing.»
  • «Microsoft Word Error 5981 failed.»
  • «Fault in Software Path: Microsoft Word Error 5981.»

Microsoft Word Error 5981 EXE errors happen during Microsoft Word installation, while running Microsoft Word Error 5981-related applications (Microsoft Word), during startup or shutdown, or during installation of Windows OS. Notating when Microsoft Word Error 5981 errors occur is paramount in finding the cause of the Microsoft Word problems and reporting them to Microsoft Corporation for help.

Problem Sources of Microsoft Word Error 5981

Microsoft Word Error 5981 problems can be attributed to corrupt or missing files, invalid registry entries associated with Microsoft Word Error 5981, or a virus / malware infection.

Especially, Microsoft Word Error 5981 errors stem from:

  • Microsoft Word Error 5981 entry invalid or corrupt.
  • Virus or malware infection that has corrupted the Microsoft Word Error 5981 file or related Microsoft Word program files.
  • Another program maliciously or mistakenly deleted Microsoft Word Error 5981-related files.
  • Another program conflicting with Microsoft Word Error 5981 or another Microsoft Word shared reference.
  • Incomplete or corrupt Microsoft Word (Microsoft Word Error 5981) from download or installation.

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

Понравилась статья? Поделить с друзьями:
  • Error 5899 metadata file missing of damaged 1 cs16
  • Error 5889 metadata file missing or damaged 1
  • Error 5805 p cad
  • Error 5185 local server connections are restricted in this environment
  • Error 517 roblox что значит