+ Reply to Thread
Results 1 to 4 of 4

Debug error occurring only under a certain set of conditions

  1. #1
    Registered User
    Join Date
    01-20-2021
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    3

    Debug error occurring only under a certain set of conditions

    Hello Everyone,

    First post here. I am having a debug error occur only under a certain set of conditions. Below the bolded/underlined code is where the debug tool highlights the error:

    Please Login or Register  to view this content.
    When the code first checks if a folder exists based on certain criteria, and a folder IS created, the the debug error occurs on the Bolded/Underlined code. If a folder already exists and does not need to be created, then the code runs smoothly and no debug errors. Another caveat, when the debug error occurs, the save is successful... the file is in the newly created folder.

    I am stumped as to why this is occurring only when a folder is created.

    Thank you,
    Tyler
    Last edited by TylerExcel; 01-20-2021 at 04:24 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Debug error occurring only under a certain set of conditions

    I'm not sure what the exact problem is, but the code seems overly complex. Maybe try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-20-2021
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Debug error occurring only under a certain set of conditions

    Thank you Alpha Frog with your simplified code. But I am still getting the same error. On your code, the bolded/underlined is what caused the debug error.

    Please Login or Register  to view this content.
    The debug error only occurs when it has to create a new folder "MkDir". If it does not need to make a new folder, there is no debug error. For example, I ran the simplified code in the circumstance that a new folder needs to be created. I then received a debug error, closed the debug box and performed the same operation. On the second run, a folder did not need to be created (as it was already created on the first debug run). I was prompted if I wanted to overwrite the file, selected yes, and the code ran smoothly without a debug.

    On a side note, the pathway folder is a onedrive folder. Could a onedrive sync issue be occurring when a new folder is created, like when it attempts to save on the pathway with a newly created folder, it errors. But an already created AND synced folder does not have the issue?

    Thank you,
    Tyler

    End Sub
    Last edited by TylerExcel; 01-20-2021 at 04:23 PM.

  4. #4
    Registered User
    Join Date
    01-20-2021
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Debug error occurring only under a certain set of conditions

    What confuses me the most is how there really is no error. When an error code is thrown, the action is still performed (New folder created, file saved in folder). The debug error code should not occur.

    Closing out of the debug, re-running macro, saving over file - is the only workaround for the entire macro to work.

+ 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. DeBug error
    By Turtle1219 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-24-2018, 11:33 AM
  2. Coding to insert a message in excel as opposed to a error occurring
    By chrisellis250 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 05-09-2017, 11:20 AM
  3. [SOLVED] How to fix an error occurring within this VBA function? (ERR91: Obj/With Variable Not Set)
    By jmccoughlin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2015, 11:55 PM
  4. VBA Code Runs in Debug Mode But Returns Type Mismatch Error Outside Debug Mode
    By valerie.k.chiang in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2014, 03:48 PM
  5. Argument not optional error is occurring in goal seek automated code.
    By bk1202 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2013, 08:32 AM
  6. Debug error
    By stuntmannen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-07-2010, 10:45 AM
  7. Debug error 13
    By BillGoodman in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 06-23-2009, 03:12 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