1

I'm using VBA in Excel to loop through files on a sharepoint site and open all Excel files.

The code crashes Excel the first time I run it, however, if I then reopen it it works fine.

Are there any known issues around this?

Thanks.

Edit: Here is the code:

Sub Refresh()

    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False

        Dim fso As FileSystemObject
        Dim fldr As Folder
        Dim f As File
        Dim wb As Workbook

        Set fso = New FileSystemObject
        Set fldr = fso.GetFolder(SharePointSite)

        For Each f In fldr.Files

            Set wb = Workbooks.Open(SharePointURL & f.Name)

        Next f

        Set wb = Nothing
        Set fldr = Nothing
        Set fso = Nothing

        .DisplayAlerts = True
        .ScreenUpdating = True
    End With

End Sub
12
  • 1. Does it crash with an error? If so - what kind of error? 2. Could you post your code please? Have you put any defence coding? Commented Aug 31, 2012 at 15:30
  • Thanks for the reply. No error comes up, Excel just crashes. I've put the code in the original post. Cheers. Commented Aug 31, 2012 at 15:36
  • oh, could you let us know versions of Excel and SharePoint? I believe there were some issues with compability between Excel 2003 and latest version of SharePoint. Commented Aug 31, 2012 at 15:45
  • 1
    Have you tried mapping sharepoint to a drive letter and using that reference instead of the URL? Commented Sep 6, 2012 at 14:20
  • 1
    Just tried this and it solved the issue. Thanks! Commented Sep 20, 2012 at 14:36

1 Answer 1

2

Instead of mapping the document library to a drive letter try using the WebDAV address to access the library in your code. This way if the macro is distributed no one will be dependent upon having the "Z:" drive being mapped to a specific location

Set your FilePath variable equal to a string like this (use @SSL for HTTPS sites):

\\sharepoint.site.com@SSL\DavWWWRoot\site1\usersite\Book2\Shared%20Documents

If you are going to access the text file directly then set it up like this:

\\sharepoint.site.com@SSL\DavWWWRoot\site1\usersite\Book2\Shared%20Documents \Test_Text1.txt

Take a look at this blog post for a full explanation on retrieving the WebDAV path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.