programing

Excel VBA 폴더 열기

telecom 2023. 6. 14. 21:40
반응형

Excel VBA 폴더 열기

2010 Excel VBA 사용 - 서브를 통해 폴더를 열려고 합니다.내가 여기서 뭘 잘못하고 있는 거지?

VBA

Sub openFolder()  
  Dim preFolder As String, theFolder As String, fullPath as String

    theFolder = Left(Range("T12").Value, 8)
    preFolder = Left(Range("T12").Value, 5) & "xxx"
    fullPath = "P:\Engineering\031 Electronic Job Folders\" & preFolder & "\" & theFolder

    Shell(theFolder, "P:\Engineering\031 Electronic Job Folders\" & preFolder, vbNormalFocus)

End Sub

Windows 파일 탐색기를 열려면 탐색기를 호출해야 합니다.exe

Call Shell("explorer.exe" & " " & "P:\Engineering", vbNormalFocus)

등가 구문

Shell "explorer.exe" & " " & "P:\Engineering", vbNormalFocus

이를 사용하여 워크북을 열고 워크북의 데이터를 템플릿에 복사합니다.

Private Sub CommandButton24_Click()
Set Template = ActiveWorkbook
 With Application.FileDialog(msoFileDialogOpen)
    .InitialFileName = "I:\Group - Finance" ' Yu can select any folder you want
    .Filters.Clear
    .Title = "Your Title"
    If Not .Show Then
        MsgBox "No file selected.": Exit Sub
    End If
    Workbooks.OpenText .SelectedItems(1)

'아래는 워크북의 새 시트에 파일을 복사하고 시트 1에 해당 값을 붙여넣는 것입니다.

    Set myfile = ActiveWorkbook
    ActiveWorkbook.Sheets(1).Copy after:=ThisWorkbook.Sheets(1)
    myfile.Close
    Template.Activate
    ActiveSheet.Cells.Select
    Selection.Copy
    Sheets("Sheet1").Select
    Cells.Select
    ActiveSheet.Paste

End With

언급URL : https://stackoverflow.com/questions/17426704/excel-vba-open-a-folder

반응형