1. FAQ
  2. 엑셀(Excel)
  3. AfterEffects
  4. Premiere
  5. Photoshop
  6. ETC

이 게시판은 아별닷컴 회원만 질문을 올릴 수 있습니다. 회원에게 주어지는 특권인셈이지요. 회원이 아닌 분들은 열람만 가능합니다.

[레벨:30]아별

2012.08.16 16:46

엑셀대단해님~ 안녕하세요?

 

신규파일의 생성은 의외로 쉽습니다.

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

 

문서 첨부 제한 : 0Byte/ 2.00MB
파일 제한 크기 : 2.00MB (허용 확장자 : *.*)