从硬盘打开csv文件而不提供csv文件的位置

时间:2012-07-26 20:38:43

标签: vba excel-vba excel

如何使用VBA从硬盘打开csv文件而不提供文件的特定位置。

1 个答案:

答案 0 :(得分:0)

Sub GetCSV()

    Dim sFile As String
    Dim wb As Workbook

    'You can get fancier with the "filter" argument, see the internet for more info
    sFile = Application.GetOpenFilename("*.csv,*.csv")

    'False means they clicked cancel
    If sFile <> "False" Then
        Set wb = Workbooks.Open(sFile)
        'do stuff
        wb.Close
    End If

End Sub