I am trying to send key strokes to an open Microsoft Acess file so that I can export data to an excel file via the toolbar. How can I activate the open Access file in VBA code so that it is the window of focus?
You can activate the open Access application using AppActivate
and the title of the window.
The title of the window, however, depends on what's currently open:
If no database is open:
AppActivate GetObject(, "Access.Application").Name 'Or AppActivate "Microsoft Access"
If a database is open that doesn't have a custom title:
AppActivate GetObject(, "Access.Application").CurrentDb.Name 'Or AppActivate "FileName.accdb"
If a database is open that has a custom title:
AppActivate GetObject(, "Access.Application").CurrentDb.Properties!AppTitle 'Or AppActivate "The title"
Do note that automating Access using SendKeys is doing it wrong in my opinion. Access has an object model just like Excel, and you can link the two really easily using COM. It's generally way more reliable than using SendKeys,