PDA

View Full Version : Word 2013 Create folders and files in a network drive



LLC
03-07-2016, 12:34 PM
Since the change to Windows 10/Word 2013, I can't use the drive letter to create folders and files in the network.

For example:

I used to use "W:\CLIENTS\ but now it doesn't recognize W:

I need to create new folders and files using VBA code. HELP! Thanks so much for any help.

gmayor
03-07-2016, 09:59 PM
There should be no reason why you cannot create folders on your network, using the network drive letter, provided you have write access to the particular network drive. Ensure that the drive is in the same workgroup as the PC running the macro. Then the following will work:


Option Explicit

Sub Macro1()
CreateFolders "W:\Path\Test\"
End Sub

Private Function FolderExists(strFolderName As String) As Boolean
'Graham Mayor
'strFolderName is the name of folder to check
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(strFolderName)) Then
FolderExists = True
Else
FolderExists = False
End If
lbl_Exit:
Exit Function
End Function

Private Function CreateFolders(strPath As String)
'Graham Mayor
'Create any missing folders in a named file path
Dim strTempPath As String
Dim lngPath As Long
Dim vPath As Variant
vPath = Split(strPath, "\")
strPath = vPath(0) & "\"
For lngPath = 1 To UBound(vPath)
strPath = strPath & vPath(lngPath) & "\"
If Not FolderExists(strPath) Then MkDir strPath
Next lngPath
lbl_Exit:
Exit Function
End Function

LLC
03-08-2016, 01:59 PM
Hello Graham!

thanks for this help. I stepped thru the code and here is where I am fuzzy.

How do I create the following folders on the already existing W:\Clients?

First folder is going to be a variable from which the user answers
Second folder and all of the other ones are specifically named Pleadings, Insurance Reports, DORA, etc.
Where do I put that within your code?
Thanks again!
Christine

gmaxey
03-08-2016, 03:38 PM
Sub Macro1()
Dim strFolder As String
strFolder = InputBox("What folder do you want to add?", "New Folder")
CreateFolders "W:\Clients\" & strFolder
CreateFolders "W:\Clients\" & strFolder & "\Pleadings"
CreateFolders "W:\Clients\" & strFolder & "\Insurance Reports"
'And so on.
End Sub

LLC
03-14-2016, 12:05 PM
Do you guys write VBA for people? How much per hour. I would rather you do it than wasting my novice attempts hours!

gmaxey
03-14-2016, 12:46 PM
Yes, Graham and I both offer paid development services. If you want to discuss rates please contact one of us via our website contact/feedback links.

http://gregmaxey.mvps.org/word_tips.html or http://www.gmayor.com/Word_pages.htm