■99285 / inTopicNo.1) |
SharePointをネットワークドライブに設定 |
□投稿者/ 白子誠 (1回)-(2022/03/03(Thu) 10:32:33)
|
分類:[VB.NET/VB2005 以降]
環境は
OS:Win10(64bit)
VS:2019
SharePoint上のファイルとフォルダーを検索する為、
一時的にSharePointをネットワークドライブに設定したいですが、
VBAでは以下クラスを使って問題なくできました。
Option Explicit
Private oMappedDrive As Scripting.Drive
Private oFSO As New Scripting.FileSystemObject
Private oNetwork As New WshNetwork
Private Sub Class_Terminate()
UnmapDrive
End Sub
Public Function MapDrive(NetworkPath As String) As Scripting.folder
Dim DriveLetter As String, i As Integer
UnmapDrive
For i = Asc("Z") To Asc("A") Step -1
DriveLetter = Chr(i)
If Not oFSO.DriveExists(DriveLetter) Then
oNetwork.MapNetworkDrive DriveLetter & ":", NetworkPath
Set oMappedDrive = oFSO.GetDrive(DriveLetter)
Set MapDrive = oMappedDrive.RootFolder
Exit For
End If
Next i
End Function
Private Sub UnmapDrive()
If Not oMappedDrive Is Nothing Then
If oMappedDrive.IsReady Then
oNetwork.RemoveNetworkDrive oMappedDrive.DriveLetter & ":"
End If
Set oMappedDrive = Nothing
End If
End Sub
そのままVBへ転用したいので、
以下のクラスをVB上で実施した結果、
「oNetwork.MapNetworkDrive(DriveLetter & ":", NetworkPath)」のところで
「The operation being request was not performed because the user has not been authenticated. HRESULT: 0x800704DC」
のエラーが発生しました。
Excel上は問題なかったのに、なんでVBでエラーが発生するか理解不能です。
どなたか問題点を教えて頂けますか?
Public Class SharePoint
Private oMappedDrive As Scripting.Drive
Private oFSO As New Scripting.FileSystemObject
Private oNetwork As New IWshRuntimeLibrary.IWshNetwork_Class
Private Sub Class_Terminate()
UnmapDrive()
End Sub
Public Function MapDrive(NetworkPath As String) As Scripting.Folder
Dim DriveLetter As String, i As Integer
UnmapDrive()
For i = Asc("Z") To Asc("A") Step -1
DriveLetter = Chr(i)
If Not oFSO.DriveExists(DriveLetter) Then
oNetwork.MapNetworkDrive(DriveLetter & ":", NetworkPath)
oMappedDrive = oFSO.GetDrive(DriveLetter)
MapDrive = oMappedDrive.RootFolder
Exit For
End If
Next i
End Function
Private Sub UnmapDrive()
If Not oMappedDrive Is Nothing Then
If oMappedDrive.IsReady Then
oNetwork.RemoveNetworkDrive(oMappedDrive.DriveLetter & ":")
End If
oMappedDrive = Nothing
End If
End Sub
End Class
因みにNetworkPathはVBAもVBも同じ以下格式を使っています。
"https://XXXX.sharepoint.com/sites/XXXX/Shared%20Documents"
|
|