我创建了一个数据库,使用MSExcel作为前端,使用MSAccess作为后端。 MSAccess文件位于“共享网络文件夹”中,该文件夹需要我已经拥有的用户名和密码。为了使其他无法访问“共享网络文件夹”的人使用该文件,我想使用VBA代码在MSExcel文件中注入自己的用户名/密码。
我使用此方法,但仍显示此错误-2147023677:Access Shared Network Folder
Public Sub TestNetShareName()
Dim NetworkObject As Object
Dim FSO As Object
Dim Directory As Object
Dim Filename As Object
Dim ServerShare As String
Dim UserName As String
Dim Password As String
ServerShare = "\\10.226.2.55\Dept_Share\MHE"
UserName = "mydomain\myuser"
Password = "password1234"
Set NetworkObject = CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
Set Directory = FSO.GetFolder(ServerShare)
For Each Filename In Directory.Files
Debug.Print Filename.Name
Next
Set Filename = Nothing
Set Directory = Nothing
Set FSO = Nothing
NetworkObject.RemoveNetworkDrive ServerShare, True, False
Set NetworkObject = Nothing
End Sub