Workbooks.Add하셔서 새로운 웍북을 만드시고.. 원하시는 경로에 SaveAs해주시면 새로운 파일이 생깁니다.
특정 경로에 파일이 있으면 Open해주고 아니면 새로 만들어주는 코드입니다.
해당 경로에 해당하는 폴더가 없으면 차례 차례 만들어 주는 코드도 포함되어 있사오니..
공부하시기 바랍니다. ^^
Sub openOrMakeFile() '### Created by abyul.com 2012.08.16 Dim strPath As String, strFile As String strPath = "D:\Secret\Hot\Cool\" strFile = "아별닷컴쵝오.xlsx" If Right(strPath, 1) <> Application.PathSeparator Then strPath = strPath & Application.PathSeparator Dim i As Integer, intPosition As Integer: intPosition = 4 For i = 1 To UBound(Split(strPath, "\")) - 1 If Dir(Left(strPath, InStr(intPosition, strPath, "\")), vbDirectory) = Empty Then MkDir Left(strPath, InStr(intPosition, strPath, "\")) End If intPosition = InStr(intPosition, strPath, "\") + 1 Next i If Dir(strPath & strFile) = Empty Then Workbooks.Add ActiveWorkbook.SaveAs strPath & strFile Else Workbooks.Open strPath & strFile End If End Sub
엑셀대단해님~ 안녕하세요?
신규파일의 생성은 의외로 쉽습니다.
Workbooks.Add하셔서 새로운 웍북을 만드시고.. 원하시는 경로에 SaveAs해주시면 새로운 파일이 생깁니다.
특정 경로에 파일이 있으면 Open해주고 아니면 새로 만들어주는 코드입니다.
해당 경로에 해당하는 폴더가 없으면 차례 차례 만들어 주는 코드도 포함되어 있사오니..
공부하시기 바랍니다. ^^
Sub openOrMakeFile()
'### Created by abyul.com 2012.08.16
Dim strPath As String, strFile As String
strPath = "D:\Secret\Hot\Cool\"
strFile = "아별닷컴쵝오.xlsx"
If Right(strPath, 1) <> Application.PathSeparator Then strPath = strPath & Application.PathSeparator
Dim i As Integer, intPosition As Integer: intPosition = 4
For i = 1 To UBound(Split(strPath, "\")) - 1
If Dir(Left(strPath, InStr(intPosition, strPath, "\")), vbDirectory) = Empty Then
MkDir Left(strPath, InStr(intPosition, strPath, "\"))
End If
intPosition = InStr(intPosition, strPath, "\") + 1
Next i
If Dir(strPath & strFile) = Empty Then
Workbooks.Add
ActiveWorkbook.SaveAs strPath & strFile
Else
Workbooks.Open strPath & strFile
End If
End Sub