+ Reply to Thread
Results 1 to 7 of 7

DIR command returns Bad file name or number error

  1. #1
    Registered User
    Join Date
    10-18-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    4

    DIR command returns Bad file name or number error

    Hi,

    I have a few lines of code which check to see if a file exists on our sharepoint and then if it doesn't it gives a message and closes the macro or if it does exist it opens the file. I get a run time error on the DIR part of the code. The workbooks.open code works fine on its own so the file path is ok. The DIR part of the code does work if I first go into the sharepoint and open the folder, then the code works fine. Then if I close excel and re open the code doesn't work again. Is there an alternative I can use instead of DIR to find out if a file exists or another idea? I've replaced the actual sharepoint file path with the words sharepoint address and folders etc

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 10-18-2018 at 04:09 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: DIR command returns Bad file name or number error

    I do not have experience in doing this with SharePoint files but if your Open function works then try this.
    Please Login or Register  to view this content.
    By the way, your code is suspicious because of the capitalization. It is better to copy and paste your code into a post rather than type it in.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-18-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    4

    Re: DIR command returns Bad file name or number error

    Thanks, I had to type it because I'm using my home pc to post on the forum as cant access from my work laptop and we are not allowed to email to our personal email from work email. All quite long winded and frustrating!

    Does the on error cover just the part of the macro which is trying to open the file or all of the page, my macro was quite long and if something else fails don't want to all join in or could I separate this part into its own sub I guess.

    Just tried your code, the problem is excel gives an error window which says "we cant connect to //etc etc.xlsx. please make sure you're using the correct web addess" this is a message which once you then click ok, the file not on sharepoint message box than comes up. Is there a way to disable the excel warning message before? If there is then this is perfect

  4. #4
    Registered User
    Join Date
    10-18-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    4

    Re: DIR command returns Bad file name or number error

    Just to add to this as well, the DIR code does work if I go into the folder on the sharepoint manually first before running the DIR code.

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: DIR command returns Bad file name or number error

    I may be wrong here but I am not sure DIR works with external links to files.

    If it does I imagine you need to login to SharePoint to access these files? If so DIR doesn't pass credentials and likely doesn't have permissions as a guest/unknown/anonymous "user" to get to the file.

    It also occurs to me you may need to replace certain characters with their HTML representation in the URL. For example space is %20.

    A quick google search suggests there may be alternate ways to do this which may provide you with more options for how you pass info like credentials and how you return info. Here is an example using MSXML2.XMLHTTP.6.0 objects instead of DIR or FSO: https://social.technet.microsoft.com...repointgeneral
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  6. #6
    Registered User
    Join Date
    10-18-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    4

    Re: DIR command returns Bad file name or number error

    Thanks, its an internal sharepoint so we're always signed in. For the URL, the path works with the Open code, just not with the DIR, although I have experimented all afternoon with adding %20's %2R's / \ and every combination

    I think the solution to use on error will work, just need to get rid of the excel warning message now that pops up

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: DIR command returns Bad file name or number error

    Quote Originally Posted by longandtallpaul View Post
    Does the on error cover just the part of the macro which is trying to open the file or all of the page, my macro was quite long and if something else fails don't want to all join in or could I separate this part into its own sub I guess.
    I assumed this code was your whole sub. If not we need to start again. Comments in green, additional code in red.

    Please Login or Register  to view this content.
    Just tried your code, the problem is excel gives an error window which says "we cant connect to //etc etc.xlsx. please make sure you're using the correct web addess" this is a message which once you then click ok, the file not on sharepoint message box than comes up. Is there a way to disable the excel warning message before? If there is then this is perfect
    I don't know where that message is coming from. I do have access to SharePoint, just never tried to do anything like this. I'll set up a test and what I can figure out.

+ 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. Kill command & Path/File access error (Error 75)
    By bongaan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2021, 08:21 PM
  2. Replies: 0
    Last Post: 11-15-2016, 02:38 PM
  3. WorksheetFunction.Match returns error with String variable, but not with number
    By IntisarN in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2015, 03:38 PM
  4. Replies: 1
    Last Post: 05-07-2014, 07:05 AM
  5. [SOLVED] How to stop error when I cancel the input file source command?
    By XxCMoneyxX in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-15-2013, 03:23 PM
  6. returns covariance MMULT command
    By marco2011 in forum Excel General
    Replies: 0
    Last Post: 04-07-2010, 01:47 AM
  7. Kill Command - file not found error
    By chris100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2010, 02:55 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