I'm trying to create a deployment tool using excel and VBA. The spreadsheet contains an Administrative share path ie (\\\\G5RCJ55\\C$\\users\\public\\desktop\\file.txt) I have administrative rights. I pull the path using VBA and tried using dir() but that fails.
Any suggestions on how I can:
1. Check if a file exists
2. If not, copy a file to the target machine/directory (The public desktop on the C: Drive).
Sub deployToDesktop(cnt As Integer)
Dim fullPath As String: fullPath = Cells(cnt, "D").value & "\" & Cells(cnt, "E").value
MsgBox ("Admin path " & fullPath)
If Not Dir(fullPath) Then
MsgBox (fullPath)
End If
End Sub
OK Found an answer. I need to use the FileSystemObject. This understands UNC path files. Here is the updated code:
Sub deployToDesktop(cnt As Integer)
Dim fso As New FileSystemObject
Dim fullPath As String: fullPath = Cells(cnt, "D").value & "\"
If fso.FolderExists(fullPath) Then
MsgBox ("Exists " & fullPath)
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.