2016-07-15 89 views
0

當我使用下面的代碼時,沒有文件被複制到sharepoint,但代碼不顯示錯誤。有人可以幫我嗎?將文件上傳到分享點:VBA

Dim SharepointAddress As String 
Dim LocalAddress As String 
Dim objNet As Object 
Dim FS As Object 

SharepointAddress= "\\xxxx\sites\xxx\xxx"    
' Where you will enter your location path 
LocalAddress = "yourfile path\test.xlsx"          
' Where you will enter the file path, e.g.: Excel file 
Set objNet = CreateObject("WScript.Network") 
Set FS = CreateObject("Scripting.FileSystemObject") 
If FS.FileExists(LocalAddress) Then 
FS.CopyFile LocalAddress, SharepointAddress 
End If 
Set objNet = Nothing 
Set FS = Nothing 
+0

有人可以建議一些替代方法,或幫我解決這個查詢 – user1553562

+0

如果不拋出一個錯誤,你確定你正在使用正確的道路? –

+0

是benno..the文件路徑是正確的..我需要指定文件的名稱,同時給予本地地址路徑? – user1553562

回答

0

嘗試以下提到的電源外殼步驟上傳您的文檔,或嘗試複製和過去的文檔通過資源管理器視圖

$WebURL = <site url(http://portal.contoso.com/sites/stuff)> 
$DocLibName = "<document library name>" 
$FilePath = "file path(your local machine)" 
$Web = Get-SPWeb $WebURL 
$List = $Web.GetFolder($DocLibName) 
$Files = $List.Files`enter code here` 
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1) 
$File= Get-ChildItem $FilePath 
$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) 
$web.Dispose() 
0

解決方法1(使用命令行管理程序複製到WebDAV的目錄):

Shell "cmd.exe /k net use x: http://spsite/doclib" 
Shell "cmd.exe /k copy c:\file.doc x:" 
Shell "cmd.exe /k net use x: /delete" 

解決方法2:

使用VBA殼牌與一些控制檯應用程序,做到無覆蓋它例如WinSCP賦予或DavCopy或捲曲,甚至PowerShell的UT淨驅動 (見more