smartpat19
Board Regular
- Joined
- Sep 3, 2014
- Messages
- 114
Hi, This macro allows the user to select a folder and loop a macro through each excel file in the folder. This works fine on my own hard drive but the moment i select a folder on the network it just go straight to saying the "task is complete". It appears that it doesn't see any excel files in the folder.
Code:
'Retrieve Folder Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
' Cancel
NextCode:
myPath = myPath
'File Extension (must include wildcard "*")
myExtension = "*.xls"
'Target Path with Ending Extention
myFile = Dir(myPath & myExtension)
'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(Filename:=myPath & myFile, ReadOnly:=True, UpdateLinks:=False)
'macro code here
'End Macro
'Save and Close Workbook
wb.Close SaveChanges:=True
'Get next file name
myFile = Dir
Loop
Application.DisplayAlerts = False
B.Delete
X.Close SaveChanges:=True
Application.DisplayAlerts = True
MsgBox "Task Complete!"
End Sub