Hello!
The excel file I am currently working on uses Vlookups in the worksheet to automatically pull about 70% of the information into a userform, the rest is input manually by a Control Room Operator. Unfortunately the folder, lets call it Folder C, that houses the information that the vlookups pull data from is password protected which is making me run into an issue. All of these files are on a company server and administration can access Folder C if they have it mapped but those who input data from our control room can not. I worked on a code that plugged in the username and password as soon as the document was opened so we didn't have to give out the login info. This caused a popup to say that we could not login in twice when it was opened on a computer with Folder C already mapped. So I'm thinking an If Then statement code could solve this.
This is what I have so far but I run into a "runtime error '424' Object Required" which highlights the line with the bold red underlined text. Any ideas how to fix this issue? Thanks so much in advance!!
Sub Autpen()
'''start of trial
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 = "Redacted"
UserName = "redacted"
Password = "redacted"
Set NetworkObject = CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(ServerShare) Then
NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
End If
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
ActiveWorkbook.RefreshAll[/CODE][/CODE]
The excel file I am currently working on uses Vlookups in the worksheet to automatically pull about 70% of the information into a userform, the rest is input manually by a Control Room Operator. Unfortunately the folder, lets call it Folder C, that houses the information that the vlookups pull data from is password protected which is making me run into an issue. All of these files are on a company server and administration can access Folder C if they have it mapped but those who input data from our control room can not. I worked on a code that plugged in the username and password as soon as the document was opened so we didn't have to give out the login info. This caused a popup to say that we could not login in twice when it was opened on a computer with Folder C already mapped. So I'm thinking an If Then statement code could solve this.
This is what I have so far but I run into a "runtime error '424' Object Required" which highlights the line with the bold red underlined text. Any ideas how to fix this issue? Thanks so much in advance!!
Sub Autpen()
'''start of trial
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 = "Redacted"
UserName = "redacted"
Password = "redacted"
Set NetworkObject = CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(ServerShare) Then
NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
End If
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
ActiveWorkbook.RefreshAll[/CODE][/CODE]