vbams-accesscommandbar

MSACCESS - How to trigger the Excel's import/export wizard via VBA (CommandBarButton)


I have a form with a button that HAS to trigger the classic Excel's import/export wizard via VBA.

enter image description here

I tried to list all the CommandBar in order to identify the one i need and next the Excel's CommandBarButton, so i can use it for a function. i did like this:

Public Function ListCommBars()
Dim cbrBar As CommandBar
'Dim ctlBar As CommandBarButton
'Dim cbrBars As CommandBars
'Dim strVal As String

For Each cbrBar In CommandBars

    Debug.Print cbrBar.Name, cbrBar.NameLocal, cbrBar.visible
Next

End Function

but this function returns a list of bars i can't recognize on my current commandbars.. my goal is to call the Excel's import/export CommandBarButton and trigger it via VBA.

How can i do that?


Solution

  • Maybe you want:

    DoCmd.RunCommand acCmdExportExcel

    or

    DoCmd.RunCommand acCmdImportAttachExcel

    Calling CommandBars is deprecated method. Only time I've ever used it is for:
    CommandBars.ExecuteMso "DataRefreshAll"