+ Reply to Thread
Results 1 to 3 of 3

VBA Code to Skip to Next Macro if File Doesn't Exist

  1. #1
    Registered User
    Join Date
    08-06-2012
    Location
    Louisville, KY
    MS-Off Ver
    Excel 2003
    Posts
    1

    VBA Code to Skip to Next Macro if File Doesn't Exist

    Hi Guys!
    I'm sure this isn't an uncommon situation but here goes nothing:

    I'm trying to write a code that will open different files in a directory (different names based on quarters), open the pivot table and pull the data from there. I have all the correct code to grab the data, but I want to consolidate all 4 of the scenarios. It works when the file is available in the directory, but in the event it's not there, I'm stuck.

    My question: what do I do inside the code to say if "2016Q1Q2.xlsb" doesn't exist, go to the "2016Q3Q4.xlsb" - and if that doesn't exist then End Sub? I don't want to end up with the error message.

    Thank you in advance!
    Last edited by ahankerson2; 12-10-2015 at 09:23 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code to Skip to Next Macro if File Doesn't Exist

    It would be easier to accurately suggest a method if you post the code you're currently using. Remember to use CODE /CODE tags.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: VBA Code to Skip to Next Macro if File Doesn't Exist

    Hi ahankerson and welcome to the forum,

    Read about testing for errors and branching from them at:

    http://www.cpearson.com/excel/ErrorHandling.htm

    If this doesn't help then post your code and tell us exactly what you expect.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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] Loop through a set of files and check if a file doesn't exist
    By desolatori in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-11-2014, 05:54 AM
  2. [SOLVED] Macro Pivot Table: Most elegant way to skip a "do not display" if element doesn't exist
    By Skotzmun in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2013, 05:03 AM
  3. [SOLVED] Look for a File and create one if it doesn't exist
    By Titansmasher in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-08-2012, 07:43 PM
  4. Excel links to file that doesn't exist
    By Chezterfield in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-08-2011, 07:08 AM
  5. Shared File doesn't exist
    By rvancura32 in forum Excel General
    Replies: 0
    Last Post: 02-09-2009, 01:19 PM
  6. Import Macro trying to gain acces to file that doesn't exist.
    By Jen_DPS in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-20-2006, 12:35 PM
  7. error msg of link to a file that doesn't exist
    By ayl322 in forum Excel General
    Replies: 0
    Last Post: 03-03-2005, 04:32 PM

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