Scripting to send Excel file to SharePoint

MacroAlan

New Member
Joined
Aug 30, 2004
Messages
31
My VBA just ran through and created 2 20meg Excel files and I've called the routine to send them to SharePoint.

Code:
    ' ===========  SEND to SharePoint ============================
    L = MsgBox("Do you want to send the finished files on SharePoint", vbYesNo, "SharePoint")
        If L = 6 Then
            Call AddToSharePt(ShrPtURL, RptPath, FileName)              'Raw
            Call AddToSharePt(ShrPtURL, RptPath, RptName & MyDate)     'Pretty
        End If
Above part works great. It begins to set up the transfer and stops with 'type mismatch' error:
Code:
Function AddToSharePt(SharePointURL As String, MyPath As String, MyFile As String)
    Dim fldR                As Folder
    Dim fsO                 As Scripting.FileSystemObject
    Dim F                   As File
    Dim xmlHTTP
    Dim SharePointFileName
    Dim tsIn
    Dim sBody
    Dim LlFileLength        As Long
    Dim LvarBin()           As Byte
    Dim LobjXML             As Object
    Dim LvarBinData         As Variant
    Dim PstrFullfileName    As String
    Dim PstrTargetURL       As String
    Dim Password            As String

    Set LobjXML = CreateObject("Microsoft.XMLHTTP")
    
    Set fsO = CreateObject("Scripting.FileSystemObject")


    CheckDir (MyPath)  [COLOR="#B22222"] 'Our util to verify whether dir exists[/COLOR]
    Set fldR = fsO.GetFolder(MyPath)  [B] [COLOR="#B22222"] ' <--- BLOWS up here[/COLOR][/B]
    Debug.Print fldR.Files.Count
    
    For Each F In fldR.Files
        
        If F.Name = MyFile Then
        
            SharePointFileName = SharePointURL & F.Name
                
[COLOR="#FF0000"]            '****************************   Upload text files  **************************************************[/COLOR]
            
              If Not SharePointFileName Like "*.gif" And Not SharePointFileName Like "*.xls*" And Not SharePointFileName Like "*.mpp" Then
            
                Set tsIn = F.OpenAsTextStream
                sBody = tsIn.ReadAll
                tsIn.Close
              
                Set xmlHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
                
            
                xmlHTTP.Open "PUT", SharePointFileName, False, USERNAME, Password
                xmlHTTP.Send sBody
                
              Else
            
        [COLOR="#FF0000"]    '****************************   Upload binary files  **************************************************[/COLOR]
              
                PstrFullfileName = MyPath & F.Name
                LlFileLength = FileLen(PstrFullfileName) - 1
            
            [COLOR="#FF0000"]    ' Read the file into a byte array[/COLOR].
                ReDim LvarBin(LlFileLength)
                Open PstrFullfileName For Binary As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
                Get [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , , LvarBin
                Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
            
                ' Convert to variant to PUT.
                LvarBinData = LvarBin
                PstrTargetURL = SharePointURL & F.Name
            
            
                ' Put the data to the server, false means synchronous.
                LobjXML.Open "PUT", PstrTargetURL, False, USERNAME, Password
            
               ' Send the file in.
                LobjXML.Send LvarBinData
            
              End If
              
             ' i = i + 1
             ' RetVal = SysCmd(acSysCmdSetStatus, "File " & i & " of " & totFiles & " copied...")
        End If
    
    Next F
    
    '  RetVal = SysCmd(acSysCmdClearStatus)
      Set LobjXML = Nothing
      Set fsO = Nothing
    
    
err_Copy:
    If Err <> 0 Then
      'MsgBox Err & " " & Err.Description
    End If

End Function
I have changed how the MyPath is classified everyway I can imagine and something in that line is causing a “Type mismatch”

I have 10 other programs where this is working perfectly. Help?
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top