+ Reply to Thread
Results 1 to 4 of 4

'While' function inside of error handler giving an error/failing

  1. #1
    Registered User
    Join Date
    03-25-2015
    Location
    Melbourne, VIC, AUS
    MS-Off Ver
    2013
    Posts
    17

    'While' function inside of error handler giving an error/failing

    Hi All,

    I have the following code extract, its opening a workbook however if it does not exist i want it to then find and open the latest file however its not working and just saying that it cant open the file with today's date?

    Can someone please tell me where i am going wrong?

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    11-25-2013
    Location
    Western Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: 'While' function inside of error handler giving an error/failing

    It's working for me, as long as I have a correctly named document in the location specified.

    When I set the path to C:\Temp\ and run the code it gives run-time error '1004' because it can't find C:\Temp\qryDAConsumption 221015.xlsx and when I place a file with that name in C:\Temp it successfully opens the file. Is there any change that your file name is not exactly the same as the code is setting it? Maybe an extra space in it, or something like that?

  3. #3
    Registered User
    Join Date
    03-25-2015
    Location
    Melbourne, VIC, AUS
    MS-Off Ver
    2013
    Posts
    17

    Re: 'While' function inside of error handler giving an error/failing

    Hi Larena,

    Thanks for looking into this, yes it will work with the current days date but if the file with the current days date is not present it is supposed to search back day by day until it finds the latest file.

    In this case the file i do have available is "qryDAConsumption 201015.xlsx" but its not doing the search part. Its just throwing an run-time error saying it cannot find "I:\Transaction Reports\Supply Outlook Inputs\qryDAConsumption 221015.xlsx".

  4. #4
    Registered User
    Join Date
    11-25-2013
    Location
    Western Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: 'While' function inside of error handler giving an error/failing

    Hi again,
    It seems that you can't handle an error within an error (I'd never thought to try), so you need to pull all of the code out of the error. After changing it as below it is going back through previous days if the file isn't found. The paste is failing, but I haven't looked into that because I assume it's to do with the dummy empty files I'm using to test with.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need error handler code to avoid pivot table refreshing error if no data is available
    By adelkam in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-04-2015, 12:37 PM
  2. Getting Run-time Error 91. Error handler not working.
    By rbs123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2014, 04:20 AM
  3. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  4. my function is giving value error
    By danielgri14 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2011, 11:34 PM
  5. [SOLVED] Form Err.Raise error not trapped by entry procedure error handler
    By jchauvin@panix.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2006, 06:25 AM
  6. Function giving error
    By Martin in forum Excel General
    Replies: 3
    Last Post: 10-01-2005, 08:05 AM
  7. Function giving Error
    By Martin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-30-2005, 11:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1