To create folders using VBA
Hello,
When I try to save an excel file using VBA and the folder name mentioned in the filepath is not available, then excel gives a error message..is there any way to force excel to crate the folder and the save the file accordingly.. I use FilesystemObject to create folders now...but just wanted to know if there is any other way of doing the same!! Thanks, Sri |
Sub test()
If Not FolderExists("C:\Bob") Then MkDir "C:\Bob" End If End Sub '----------------------------------------------------------------- Function FolderExists(Folder) As Boolean '----------------------------------------------------------------- Dim sFolder As String On Error Resume Next sFolder = Dir(Folder, vbDirectory) If sFolder < "" Then If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then FolderExists = True End If End If End Function -- HTH RP (remove nothere from the email address if mailing direct) "Sri" wrote in message ... Hello, When I try to save an excel file using VBA and the folder name mentioned in the filepath is not available, then excel gives a error message..is there any way to force excel to crate the folder and the save the file accordingly.. I use FilesystemObject to create folders now...but just wanted to know if there is any other way of doing the same!! Thanks, Sri |
All times are GMT +1. The time now is 07:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com