18

使用 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
4

2 回答 2

46

如果你想打开一个 windows 文件资源管理器,你应该调用 explorer.exe

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

等效语法

Shell "explorer.exe" & " " & "P:\Engineering", vbNormalFocus
于 2013-07-02T13:31:05.783 回答
0

我用它来打开一个工作簿,然后将该工作簿的数据复制到模板中。

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
于 2015-09-17T04:52:49.443 回答