![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
Does anyone have any code for checking to see if a folder exists and if not creating one?
|
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
|
Are you trying to get your script to "save as"?
__________________
Colin |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Look up Dir and MkDir.
Code:
If Dir("c:temp",vbDirectory) = vbNullString Then
' Folder does not exist, create one:
MkDir "c:temp"
End If
[ This Message was edited by: Russell Hauf on 2002-05-21 15:56 ] |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
Yeah
i found some code in an earlier post Sub foldercheck() On Error GoTo ErrorCheck Dim foldername As String foldername = "c:YourFolderName" ChDir foldername GoTo FolderCheckEnd ErrorCheck: If Err.Number = 76 Then GoTo MakeDir If Err.Number <> 76 Then MsgBox ("A Error happened while changing to " + foldername + " or while making that folder and the error is " + Str(Err.Number)) End MakeDir: MkDir foldername Resume FolderCheckEnd: End Sub seems to work well |
|
|
|
|
|
#5 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
Quote:
If Dir("c:temp",vbDirectory) = vbNullString Then MkDir "c:temp" |
|
|
|
|
|
|
#6 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
I'll throw out another way:
_________________ Cheers, NateO [ This Message was edited by: nateo on 2002-05-21 16:50 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|