How do I prompt the user to select the file, when using macro to import a data file into a new tab?

后端 未结 1 1997
无人及你
无人及你 2021-01-22 04:42

I have a macro that is currently creates a new sheet, and imports another excel file into this new sheet.

Data from this sheet is than pulled into other areas of the w

相关标签:
1条回答
  • 2021-01-22 05:15

    You can use GetOpenFilename:

    .SourceDataFile = Application.GetOpenFilename("Excel workbooks (*.xls), *.xls")
    

    Another option is the FileDialog object. It offers more flexibility.

    Dim fdgOpen As FileDialog
    Set fdgOpen = Application.FileDialog(msoFileDialogOpen)
    fdgOpen.Title = "Please open a data file..."
    fdgOpen.InitialFileName = "C:\MyDocuments\MyDir\"
    'Other settings...
    fdgOpen.Show
    .SourceDataFile = fdgOpen.SelectedItems(1)
    
    0 讨论(0)
提交回复
热议问题