+ Reply to Thread
Results 1 to 4 of 4

Error 52 Bad File Name when using DIR / saving PDF to SharePoint / OneDrive

  1. #1
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    221

    Error 52 Bad File Name when using DIR / saving PDF to SharePoint / OneDrive

    I created a file for a client that has (among other things) macros to save copies of various sheets as PDF files. The PDFs are saved in a specified folder that is under the folder containing the Excel file.
    Everything worked fine until they apparently moved the Excel file to a SharePoint folder, and are accessing it through OneDrive. Now when they try to save the PDF, they get a runtime error 52 (Bad file name or number).
    The code checks to see whether the standard filename already exists, and if so, it adds a sequential "Ver00" to the filename. Curiously, I have an error handler in place should an error occur during the filesave operation, but the macro is NOT reaching that error handler. So I'm thinking it's tripping the error 52 when running the Dir command. But why would this crash when the file is on SharePoint, and not when it's on a local drive? I have no experience with SharePoint / OneDrive so I am clueless on how to help. Any suggestions would be appreciated!
    By the way, neither the Subdirectory nor the RefText contain any prohibited characters.
    The code is:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,114

    Re: Error 52 Bad File Name when using DIR / saving PDF to SharePoint / OneDrive

    I have no idea about SharePoint files. Best suggestion is to put Debug.Print statements in at strategic points to a) determine where the code goes and b) display the content of the variables, specifically, CheckName.

    It won't fix it but it might point you at the root cause of the problem.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    221

    Re: Error 52 Bad File Name when using DIR / saving PDF to SharePoint / OneDrive

    More info:
    The macro crashes on the If Dir(CheckName) <> "" statement (to check if the filename already exists).
    At that point, the filepath for CheckName is https://company1.sharepoint.com/sites/Projects/Shared Documents....

    Does the Dir command fail when using filepath that is a URL? Is there some workaround?

  4. #4
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    221

    Re: Error 52 Bad File Name when using DIR / saving PDF to SharePoint / OneDrive

    More info:
    I found some info online about converting URLs to UNCs. I added code to the macro so that now the filepath for CheckName is:
    \\company1.sharepoint.com\sites\Projects\Shared Documents....
    I still get the Error 52 (bad file name) when running the DIR(CheckName) statement.
    Any ideas on why this filepath is considered "bad"? Again, there are no prohibited characters in the path or the checked filename.

+ 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] Get Sheet name, when file is stored on SharePoint/OneDrive
    By mstgier in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-23-2022, 05:30 AM
  2. Check if a file exists in onedrive/sharepoint
    By S@S in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2022, 08:15 AM
  3. Replies: 0
    Last Post: 12-21-2021, 07:25 AM
  4. [SOLVED] VBA: Show pop-up when Excel file is opened in browser (e.g. SharePoint / OneDrive)
    By kingofcamden in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-01-2021, 08:43 AM
  5. [SOLVED] Saving a file to onedrive shared network and access via onedrive online
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-09-2021, 11:56 AM
  6. VBA Code for File Location on OneDrive/SharePoint
    By Vinod Krishna.C in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-05-2021, 12:50 PM
  7. Share an excel file on onedrive/sharepoint with vba
    By ARowbot in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-05-2020, 08:29 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