+ Reply to Thread
Results 1 to 6 of 6

Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed on SharePoint

  1. #1
    Registered User
    Join Date
    05-31-2020
    Location
    Norfolk, England
    MS-Off Ver
    365
    Posts
    22

    Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed on SharePoint

    I'm seeking some advice on the use of SaveAs when saving a workbook to SharePoint.

    I have some code which creates a simple workbook, populates it with some data and saves it to a chosen destination folder. This works perfectly when a local drive is selected for the destination folder. If it's run a second time with the same destination folder, I get the usual warning that the filename already exists and, if I accept, it replaces the old file with the new copy perfectly. However, if I select a SharePoint location as the destination, after warning me that the filename already exists, I get a Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed.

    It's interesting to note however that if I sandwich the SaveAs line between On Error Resume Next ... On Error Goto 0, it does actually save the workbook. Whilst this workaround works, I don't feel comfortable knowing that there's something wrong with it. I've seen others asking about this problem, but have never managed to find a definitive cause or solution. The code below is a stripped down version of my code with just the pertinent bits... but it behaves exactly the same.

    Please Login or Register  to view this content.
    Any advice gratefully received.
    Last edited by Apollo1969; 01-28-2023 at 09:27 AM.

  2. #2
    Registered User
    Join Date
    06-04-2009
    Location
    Stourbridge
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed on SharePoint

    I've never used sharepoint but this seems to come up a few times if you search for your post title
    This poster put it down to the file already existing in SP.

    https://www.reddit.com/r/excel/comme..._just_started/

    If so it would be interesting to know if you try saving without a prompt (ovewrite existing) if it stops.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-31-2020
    Location
    Norfolk, England
    MS-Off Ver
    365
    Posts
    22

    Re: Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed on SharePoint

    It's difficult to be sure as SharePoint seems to behave inconsistently at times, but I've given this a try and if I set DisplayAlerts = False as per your code above, I obviously don't get the warning that the file already exists but I do still get the same error 1004 message and my code stops at NewWB.SaveAs. However, it looks like it does save the file, although when I open the resulting file it tells me "UPLOAD BLOCKED" and tells me to save a copy, so there definitely seems to be some sort of conflict with SharePoint.

    If I use:
    Please Login or Register  to view this content.
    I do get the "file exists" warning and it appears to save ok, but I have now noticed the same issue with "UPLOAD BLOCKED" when opening the resulting file and, in file explorer, the file seems to be stuck on sync pending indefinitely.

    In both cases, the file saves fine if the filename doesn't already exist.

    SharePoint seems to be the culprit, but it would be good to know if there's a fix for this.

  4. #4
    Registered User
    Join Date
    06-04-2009
    Location
    Stourbridge
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed on SharePoint

    Can you delete the old sharepoint file if it exists prior to saving the new one, as you intend to overwrite it anyway?

  5. #5
    Registered User
    Join Date
    05-31-2020
    Location
    Norfolk, England
    MS-Off Ver
    365
    Posts
    22

    Re: Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed on SharePoint

    Yes, I guess that would work as a workaround, but it's just frustrating that this doesn't work as you'd expect. The SaveAs function is obviously designed to look for an existing file, and it does so perfectly on a local drive, so must be something to do with SharePoint lag.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed on SharePoint


    As a reminder VBA was created near the end of last century based on his gran'pa' the BASIC created in the 80's on PC but started in the 60's
    so obviously SharePoint did not ever exist at that time !
    Just warming a couple of neurons you can first save it on a local drive
    then use a Windows feature (like FSO) to copy / move the file where necessary …

+ 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] VBA UserForm causing errors for SharePoint users
    By sk8_chris20 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2022, 08:22 AM
  2. [SOLVED] SaveAs, Error.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 02-07-2017, 09:24 AM
  3. [SOLVED] .SaveAs error for Word (Error 4198: Command Failed)
    By hoboken in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2015, 06:53 PM
  4. SaveAs File format # causing an error in Excel 2010
    By MrBill in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2014, 05:51 PM
  5. [SOLVED] SaveAS Error
    By tigerdel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-26-2012, 09:24 AM
  6. File SaveAs causing run-time error
    By c4tin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-14-2009, 12:34 PM
  7. [SOLVED] error with saveas....
    By jeramie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2006, 06:45 AM

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