Macro in Access to prompt for file path when importing file

允我心安 提交于 2019-12-12 06:14:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!