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.
Above part works great. It begins to set up the transfer and stops with 'type mismatch' error:
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?
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
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 10 other programs where this is working perfectly. Help?
Last edited: