2017-11-28 21 views
0

イメージをクリックしてVBAを使用して共有ファイルにローカルファイルをコピーしたかったのですが、今すぐSharePointのファイル&のファイルをチェックできないようです。VBA - フォルダ/ファイルがSharePointに存在しています

エクセルで画像をクリックするたびにコードを実行するたびに、SharePointでそのファイルを見つけることができなくなります。 Sorry there's no such Folder......

ドライブをマッピングしようとしましたが、完全にうまく動作しますが、エンドユーザーがドライブをマップする必要があるため、オプションではありません。 今、私はリンクを使用してSharePointに接続することを検討しています。

を使用してIE &にSharePointLinkをコピーすると問題なく動作します。しかし、私が/を使用している場合、IEはリンクを見つけることができません。

UPDATE

私は数回の試行後に\を使用している場合、IEは、ネットワーク上のファイルパスを開きます。 Chromeはファイルパスをchromeページに表示します。なぜこうなった?????

認証にはWindows認証が使用されているため、問題はありません。

これは、フォルダは、フォルダ

Function FolderCreate(ByVal path As String) As Boolean 

FolderCreate = True 
Dim FSO As New FileSystemObject 

try: 
If FSO.FolderExists(path) Then 
    Exit Function 
Else 
    On Error GoTo catch 
    FSO.CreateFolder path 
    Debug.Print "FolderCreate: " & vbTab & path 
    Exit Function 
End If 

catch: 
MsgBox "A folder could not be created for the following path: " & path & ". Check the path name and try again." 
FolderCreate = False 
Exit Function 

End Function 

すべてのヘルプを作成し、提案が高く評価されているため

Function FolderExists(ByVal path As String) As Boolean 

FolderExists = False 
Dim FSO As New FileSystemObject 

If FSO.FolderExists(path) Then FolderExists = True 

End Function 

機能が存在するかどうかをチェックするために

Sub imgClicked() 

Dim SharePointLib As String 
Dim MyPath As String 
Dim folderPath As String 
Dim objNet As Object 
Dim FSO As Object 
Dim copyPath As String 
Dim copyFilePath As String 

folderPath = Application.ThisWorkbook.path 
MyPath = Application.ThisWorkbook.FullName 

SharePointLib = "//company.com/sites/MS/10%20Mg%20Review/" 
' create new folder to store the file 
copyPath = folderPath + "\copyPath\" 

If Not FolderExists(copyPath) Then 
    FolderCreate (copyPath) 
ElseIf Not FolderExists(SharePointLib) Then 
    MsgBox "Sorry there's no such folder. Folder Path: " & vbNewLine & vbNewLine & SharePointLib & "" 
    Exit Sub 
End If 

fileName = "hello.xlsm" 
'Copy current excel file and save at the new folder created 
ThisWorkbook.SaveCopyAs copyPath & fileName 
MsgBox "Save Copy As: " + copyPath & filseName & vbNewLine & vbNewLine & "The file will be uploaded to this address: " + SharePointLib & fileName 

' Check whether the file exist in the directory 
' If exist error message 
' else copy the file from copyPath then paste at the SharePoint directory 
If Not Dir(SharePointLib & fileName, vbDirectory) = nbNullString Then 
    MsgBox "Sorry file already exist!" 
Else 
    Call FileCopy(copyPath & fileName, SharePointLib & fileName) 
    MsgBox "File has being successfuly created in SharePoint!" 
End If 

Set FSO = CreateObject("scripting.filesystemobject") 
If Right(copyPath, 1) = "\" Then 
    copyPath = Left(copyPath, Len(copyPath) - 1) 
End If 
If FSO.FolderExists(copyPath) = False Then 
    MsgBox copyPath & " doesn't exist" 
    Exit Sub 
End If 
FSO.DeleteFolder copyPath 
MsgBox "Folder has being deleted successfully!" 

End Sub 

ファンクション私のコードです。もっと情報が必要な場合はお知らせください。前もって感謝します。

+0

はい、私はSharePointLib =「\\ company.com \サイトはMS \を\ ''使用してい –

+0

@TimWilliams "MS \ 10mgのレビュー\を\ \\ company.com \サイト" 'SharePointLib =を試してみてください10 Mgレビュー\ "今すぐ。今はうまくいきますが、午前中はその道を見つけることができません。なぜしばらくして突然動くのか、何か考えていますか?私はコードをまったく変更しませんでした。 – aaa

+0

私はこの種のことを時々見たことがあります。通常、Windowsエクスプローラを開き、問題のパスに移動します。 –

答えて

1

WebClientサービスが実行されていることを確認してください。コードを使用してWebClientサービスを開始することも、スタートアップの種類を自動に設定することもできます。

WebClientサービスを実行している場合、フォルダ/ファイルテストは正常に動作します。

編集:さらに、sharepoint URLをドライブ文字にマップすると、WindowsはWebClientサービスを開始します。

Sub mapPath(str_drive as string, str_path as string) 
    If Not Len(str_drive) = 1 Then Exit Sub 
    Dim wso As Object 
    Set wso = CreateObject("WScript.Network") 
    wso.MapNetworkDrive str_drive & ":", str_path, False 
End Sub 
+0

経由で接続できるようになります。情報を提供してくれてありがとう。それは私がどこで働くことができるかを理解するのに役立ちました。私は[this](https://access-programmers.co.uk/forums/showthread.php?t = 268572)は、プロセスの説明を含む完全な解決策を持った有用な記事です。 – aaa

関連する問題