Microsoft visual basic runtime error 5174

I need to check whether a file is present in the directory. If file NOT present i should create a new one. But at run time the Excel gives an error; "Run-time error 5174: Application defined...

I need to check whether a file is present in the directory.

If file NOT present i should create a new one.

But at run time the Excel gives an error;

«Run-time error 5174: Application defined or object defined error».

Is there any exception handling technique in VBA to catch these run time error?

How can i overcome this issue so that i can create a file if non existant?

Dim savename, FileExt, FileName As String
Dim i, finalrow As Integer
Dim wdvar As Word.Application
Dim wrdDoc As Word.Document

Set wdvar = CreateObject("Word.Application")
wdvar.Visible = True         

FileName = Environ("UserProfile") & "DesktopReport.docx"
Set wrdDoc = wdvar.Documents.Open(FileName)

With wdvar
    .Visible = True
    .Activate


   .Documents.Add

R3uK's user avatar

R3uK

14.4k7 gold badges42 silver badges77 bronze badges

asked Oct 5, 2016 at 9:47

Prabhu's user avatar

add a reference to Microsoft Scripting Runtime and use the Scripting.FilesystemObject.
It has a nice handy «FileExists()» function that you can use to test if a file exists.

   Dim fso as new Scripting.FileSystemobject

   If (fso.FileExists(strPath)) Then
      debug.print "File Exists"
   Else
      debug.print "File Not Found"
   End If

answered Oct 5, 2016 at 11:06

Joe Bourne's user avatar

Joe BourneJoe Bourne

1,11410 silver badges18 bronze badges

The error handling can be done like this:

sub Main
Dim savename, FileExt, FileName As String
Dim i, finalrow As Integer
Dim wdvar As Word.Application
Dim wrdDoc As Word.Document

On Error GoTo Main_Error

Set wdvar = CreateObject("Word.Application")
wdvar.Visible = True         

FileName = Environ("UserProfile") & "DesktopReport.docx"
Set wrdDoc = wdvar.Documents.Open(FileName)

With wdvar
    .Visible = True
    .Activate


   .Documents.Add
'...
on error goto 0
exit sub
Main_error
   if err.number = 5174 then
   'you may write something here
else
   'normally a msgbox for the error 
end if
end sub

Additionally 1: if you want to create the file, you may do it from the error handler or you can simply check whether the file is existing. Depends what you want: -> http://www.rondebruin.nl/win/s9/win003.htm

Additionally 2:
do not use integers, but use long, and declare each variable on a separate line, otherwise you declare them as vars.

answered Oct 5, 2016 at 9:57

Vityata's user avatar

VityataVityata

42.1k8 gold badges55 silver badges95 bronze badges

0

Personnaly, I use this function :

Public Function File_Exist(sFilePath As String) As Boolean
    Dim sProv As String
    On Error GoTo ErrorHandler
        sProv = Dir(sFilePath, vbDirectory)

        File_Exist = (sProv <> "")
    On Error GoTo 0
    Exit Function

ErrorHandler:
    MsgBox prompt:="Error on test file= " & sFilePath & vbCrLf & _
           Err.Number & vbCrLf & Err.Description
End Function

Where do you need to use it :

If File_Exist(Filename) Then
    Set wrdDoc = wdvar.Documents.Open(Filename)
Else
    With wdvar
        .Visible = True
        .Activate

       .Documents.Add
    End With
End If

answered Oct 5, 2016 at 10:07

R3uK's user avatar

R3uKR3uK

14.4k7 gold badges42 silver badges77 bronze badges

3

Old

09-15-2013, 05:12 AM

tinfanide
tinfanide is offline

Run-time Error 5174: Open Word Documents from Excel Windows 7 64bit Run-time Error 5174: Open Word Documents from Excel Office 2010 32bit

Expert

Run-time Error 5174: Open Word Documents from Excel

 

Join Date: Aug 2011

Posts: 312

tinfanide is on a distinguished road

Default

Run-time Error 5174: Open Word Documents from Excel


Early binding; opening a Word Document from Excel VBA.
First time, no error.
Starting from then, it returns the error stated in the codes below:
How could I fix it?

Code:

Public Sub SendToWord()

Dim myWord As Word.Application
Set myWord = New Word.Application
With myWord
    .Visible = True
    ''' Run-time Error 5174
    ''' Application-defined Error or Object-defined Error
    myWord.Documents.Open Filename:="1.doc"
End With

Reply With Quote

Old

10-01-2013, 01:11 AM

Default


Quote:

Originally Posted by tinfanide
View Post

Early binding; opening a Word Document from Excel VBA.
First time, no error.
Starting from then, it returns the error

Could be a timing issue. You might need to set up a loop to test whether the Word app has loaded before continuing.

__________________
Cheers,
Paul Edstein
[Fmr MS MVP — Word]

Reply With Quote

Old

10-01-2013, 01:23 AM

tinfanide
tinfanide is offline

Run-time Error 5174: Open Word Documents from Excel Windows 7 64bit Run-time Error 5174: Open Word Documents from Excel Office 2010 32bit

Expert

Run-time Error 5174: Open Word Documents from Excel

 

Join Date: Aug 2011

Posts: 312

tinfanide is on a distinguished road

Default


Yes, it might be.

Reply With Quote

Old

10-01-2013, 07:35 AM

BobBridges's Avatar

BobBridges
BobBridges is offline

Run-time Error 5174: Open Word Documents from Excel Windows 7 64bit Run-time Error 5174: Open Word Documents from Excel Office 2010 32bit

Expert

 

Join Date: May 2013

Location: USA

Posts: 695

BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about

Default


When I google 5174 for VBA/Word, it seems always to be the file-not-found error. Are you sure you’re getting the error at the .Visible=True statement rather than the .Open statement? (Of course that doesn’t explain why the file may have disappeared, but still, first things first.)

Reply With Quote

RRS feed

  • Remove From My Forums
  • Question

  • After Office updated this morning to Word 16.9 my macros are broken. Every time a macro tries to open a file I get Run-time error 5174 saying that ,y file couldn’t be found (/users/Phil/Library/Containers/com.microsoft…). Ideas?

All replies

  • When is the new update coming for Microsoft Word? I updated my version today (currently 16.9) and it does not work any more with EndNoteX8…. at all. I have tried to fix this problem all day today. Any help?

  • After Office updated this morning to Word 16.9 my macros are broken. Every time a macro tries to open a file I get Run-time error 5174 saying that ,y file couldn’t be found (/users/Phil/Library/Containers/com.microsoft…). Ideas?

    Hi Phil,

    Recently, a version Office for Mac version 16.10 is released. I suggest you can install that update version to have a try.


    Best Regards,
    Winnie Liang


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact
    tnsf@microsoft.com.


    Click
    here to learn more. Visit the dedicated
    forum to share, explore and talk to experts about Microsoft Teams.

  • When I check for updates I get a message that I’m using the current version (16.9)

    • Proposed as answer by

      Tuesday, February 6, 2018 11:30 AM

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

About Runtime Code 5174

Runtime Code 5174 happens when Microsoft Access 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!

  • Access — DO NOT USE this tag for Microsoft Access, use [ms-access] instead
  • Runtime — Runtime is the time during which a program is running executing
  • Runtime error — A runtime error is detected after or during the execution of a program.
  • Access — Microsoft Access, also known as Microsoft Office Access, is a database management system from Microsoft that commonly combines the relational Microsoft JetACE Database Engine with a graphical user interface and software-development tools
  • Microsoft access — Microsoft Access, also known as Microsoft Office Access, is a database management system from Microsoft that commonly combines the relational Microsoft JetACE Database Engine with a graphical user interface and software-development tools

Symptoms of Code 5174 — Microsoft Access Runtime Error 5174

Runtime errors happen without warning. The error message can come up the screen anytime Microsoft Access 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 Access Runtime Error 5174 (Error Code 5174)
(For illustrative purposes only)

Causes of Microsoft Access Runtime Error 5174 — Code 5174

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

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

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

Speed Up Tip #17

Tweak the Mouse Settings:

Scroll, copy and paste and navigate faster by tweaking the default settings of your mouse. You spend most of the time using your mouse so make sure to get the most out of that little controller. Increase your productivity using free powerful utilities that will let you tweak your mouse easily.

Click Here for another way to speed up your Windows PC

  1. 03-12-2015, 10:35 AM


    #1

    aman1234 is offline


    Forum Contributor


    Runtime error 5174, File could not be found.

    Hi All

    Not sure why I am getting error message «Runtime error 5174, file could not be found
    J:SystemA.mdb;

    But I checked it and I am using the right file name and right file path so why its giving me this error message?

    Thanks


  2. 03-12-2015, 10:39 AM


    #2

    Re: Runtime error 5174, File could not be found.

    Is the «;» supposed to be at the end of the file name? I only ask because I have not seen that before in a file name.

    Last edited by gmr4evr1; 03-12-2015 at 10:43 AM.

    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 — 573PH3N H4WK1NG
    You don’t have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom


  3. 03-12-2015, 10:42 AM


    #3

    Re: Runtime error 5174, File could not be found.

    I posted a duplicate post

    Last edited by gmr4evr1; 03-12-2015 at 11:03 AM.

    Reason: Clarification


  4. 03-12-2015, 10:59 AM


    #4

    aman1234 is offline


    Forum Contributor


    Re: Runtime error 5174, File could not be found.

    Why Duplicate post?? I haven’t posted it before..


  5. 03-12-2015, 11:00 AM


    #5

    aman1234 is offline


    Forum Contributor


    Re: Runtime error 5174, File could not be found.

    Well I removed «;» sign at the end of filename and its working. But Why it displays a window to select table name and database from it??


  6. 03-12-2015, 11:06 AM


    #6

    Re: Runtime error 5174, File could not be found.

    I’m not sure about that. The file extension .mdb is a data base file, maybe it has something to do with that.

    Why Duplicate post?? I haven’t posted it before..

    Sorry, I had posted a duplicate post.


  7. 03-17-2015, 05:49 AM


    #7

    aman1234 is offline


    Forum Contributor


    Re: Runtime error 5174, File could not be found.

    Can anyone please help me in this? Thanks


  • #1

Hello all,

I have been reading this forum for years and have found much helpful information, so I am hoping that someone can help me out here. I’ve tried other solutions I found here to no effect.

What I am trying to do is provide a method for users to edit reports that are generated by an application my team developed. In order to provide the flexibility we need, the code first builds the name of the file to be opened using a string variable. Then we would open the Word document… but it keeps giving a Run-Time Error 5174 and stating that it can’t find the file.

I’ve run Debug.Print to output the string that was created and it matches character for charater with the path and file name of the report I want to open. The report exists… it just won’t open.

Here is the code we are using:

Code:

Set appMS_Word = CreateObject("Word.Application")

For Each vSelected_Iterations In colSelected_Iterations
    
With wkbData_Workbook.Sheets("Report Data")
        sReport_Name = .Range("B6").Value
        sReport_Name = sReport_Name & "ReportsExtraction Reports"
        sReport_Name = sReport_Name & .Range("B1").Value
        sReport_Name = sReport_Name & "_Extraction Report Iteration "
        sReport_Name = sReport_Name & vSelected_Iterations & ".docx"
End With
    
appMS_Word.Documents.Open Filename:=sReport_Name, Format:=wdOpenFormatAuto

Next vSelected_Iterations

I’ve even tried copying the path and file name directly from Windows Explorer and it won’t work… anything you can see?

Which lookup functions find a value equal or greater than the lookup value?

MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

  • #2

My apologies, I realized I did not post the relevant Excel and Windows version information. The application runs in Windows 7 64-bit using Excel 2010 32-bit. Thank you!

RoryA

RoryA

MrExcel MVP, Moderator


  • #4

Just a value. It’s a 6 digit identification number.

RoryA

RoryA

MrExcel MVP, Moderator


  • #5

Just a value. It’s a 6 digit identification number.

Then you appear to be missing at least the Drive information from the file path.

Понравилась статья? Поделить с друзьями:
  • Microsoft visual basic runtime error 424
  • Microsoft visual basic runtime error 2147467259 80004005
  • Microsoft visual basic runtime error 13 type mismatch
  • Microsoft visual foxpro error 1429
  • Microsoft visual basic runtime error 1004 как исправить