ifilename就是选中文件的带路径的文件名,用InStrRev(ifilename, "\"),配以left()函数就可以获得文件所在文件夹。
Sub SelectFile()Application.DisplayAlerts = False
fil = ThisWorkbook.Name
Filename = Application.GetOpenFilename("Excel 文件 ,*.xls*.xlsx")
If Filename <>False Then
aFile = Split(Filename, "\")
sfilename = aFile(UBound(aFile))
End If
Workbooks.Open (Filename)
Workbooks(sfilename).Sheets(1).Cells.Copy Workbooks(fil).Sheets(1).Cells
Workbooks(sfilename).Close
Application.DisplayAlerts = True
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)