问题
I am trying to import an Excel spreadsheet into Access 2013 using a macro. Is there a way to make the macro prompt for a file path instead of having a static file path? I would like to have a message box or something similar be provided to the user to define the file path for each Excel file they would like to import. Is there a macro for this?
回答1:
You could use a InputBox via vba
Dim p As String
p = InputBox("please input file path")
Debug.Print p
I am not sure however how to achieve the same thing with just a macro.
回答2:
Use this function:
Function seleccionarArchivo()
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
f.Filters.Clear
f.Filters.Add "Todos", "*.*"
If f.Show Then
seleccionarArchivo = f.SelectedItems.Item(1)
End If
Set f = Nothing
End Function
To try, put a button and add this in the click event:
MsgBox (seleccionarArchivo)
来源:https://stackoverflow.com/questions/30034508/macro-in-access-to-prompt-for-file-path-when-importing-file