Results 1 to 2 of 2

Sharepoint Macro Doesn't Return Error(s)

Threaded View

  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    Phoenix, az
    MS-Off Ver
    Excel 2013
    Posts
    26

    Sharepoint Macro Doesn't Return Error(s)

    I found some code that allows our office to send files to SharePoint (see below). For the most part it works just fine. However if an error occurs with Sharepoint, like the wrong password was supplied, we get no indication and the macro continues to run. It's not until we actually go to Sharepoint and look through the folders do we find that nothing was ever uploaded.

    Is there any way to either reverse this code so it can read the files back from Sharepoint after completion OR incorporate some type of error response from Sharepoint as each file is sent?

    The code used to send files up is as follows (and it works):

    Private Sub copyToSharePoint(sharepointURL As String, filePath As String)
        
        On Error GoTo errhandler
        'sharePointUrl should not end in a "/"
        'Initialize Variables
        Dim LlFileLength As Long
        Dim Lvarbin() As Byte
        Dim LobjXML As Object
        Dim LvarBinData As Variant
        Dim LstrFileName As String, PstrFullfileName As String, PstrTargetURL As String
        Dim fileName As String, lenFileName As Long
    
        Password = "xxxxxx"
        UserName = "xxxxxx"
        
        'Extract file name
        lenFileName = Len(filePath) - InStrRev(filePath, "\")
        fileName = Right(filePath, lenFileName)
        
        'Check that the webUrl ends in an "/"
        If Right(sharepointURL, 1) <> "/" Then
            sharepointURL = sharepointURL & "/"
        End If
            
        '****************************   Upload binary files  *****************
        Set LobjXML = CreateObject("Microsoft.XMLHTTP")
        
        PstrFullfileName = filePath
        LlFileLength = FileLen(PstrFullfileName) - 1
        
        ' Read the file into a byte array.
        ReDim Lvarbin(LlFileLength)
        Open PstrFullfileName For Binary As #1
        Get #1, , Lvarbin
        Close #1
        
        ' Convert to variant to PUT.
        LvarBinData = Lvarbin
        PstrTargetURL = sharepointURL & fileName
        
        ' Put the data to the server; false means synchronous.   'username & password added ++++
        LobjXML.Open "PUT", PstrTargetURL, False, UserName, Password
        
        ' Send the file in.
        LobjXML.Send LvarBinData
        
        Set LobjXML = Nothing
        
        On Error GoTo 0
        Exit Sub
        
    errhandler:
        If Err.Number = 53 Then
            MsgBox "Excel was unable to create the HR file to submit to SharePoint. " & vbNewLine & _
            "Please check that you are not running out of disk space and that no MS Office add-in is causing issues with Excel.", vbCritical, "File Error"
            Exit Sub
        Else
            MsgBox "Your HR could not be submitted to SharePoint. The following error occurred:" & vbNewLine & _
            "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error Uploading to SharePoint"
            Exit Sub
        End If
    End Sub
    Last edited by Bukovnik; 02-17-2014 at 06:29 PM. Reason: Correct posting mistakes. Sorry!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Opening SharePoint file with VBA - disable SharePoint "Contacting the server" message
    By kopite2002 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2013, 01:56 AM
  2. Replies: 0
    Last Post: 10-08-2013, 10:54 AM
  3. macro to save to sharepoint
    By vthokie2010 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-06-2011, 05:00 PM
  4. vb script to run macro in Sharepoint
    By smhelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2011, 02:55 PM
  5. saving to sharepoint using macro
    By smakatura in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-28-2011, 11:07 AM

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