Export to excel from access table loses sort order

I have a table that I need to export to excel.   Issue is that when I create a macro to export from the table it loses the sort order.  Trying to export with formatting replaces my existing spreadsheet rather than updating it.

What are my options with exporting from a query?  I do not have the same options available if I choose to export from a query instead of a table using the importexportspreadsheet option.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I would pull this from the Excel end, by defining an external datasource that points to the Acccess database and contains a SELECT statement with and ORDER BY clause.

This link https://support.office.com/en-gb/article/Use-Microsoft-Query-to-retrieve-external-data-42a2ea18-44d9-40b3-9c38-4c62f252da2e?ui=en-US&rs=en-GB&ad=GBMS Office 2010  help link
You can then choose whether to refresh the query manually or automatically every time the workbook opens.
gracie1972Author Commented:
Issue is it is a shared workbook we tried that before and it kept locking up.
OK. Is it a possibility to turn off the sharing while you refresh the data?

Can you tell us a bit more about your scenario and why the workbook is being shared. I don't use shared workbooks normally because of the restrictions

See also previous EE thread on limitations of shared workbooks
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

gracie1972Author Commented:
The shared workbook is to account for the fact if someone has it open while the query is trying to refresh the data on the backend.  We work in a large company and people leave files open all the time.  Trying to enforce this is a problem, if the workbook is open we can use the importexportspreadsheet feature which has solved this problem.

Now it just won't sort correctly.
NorieAnalyst Assistant Commented:
Can you post the macro/code that you are using to export to Excel?
Perhaps you could run the query from a second (unshared) workbook and then paste the whole sheet into the shared workbook.  I can't test this from where I'm sitting, but it would potentially mean you could get the data sorted and formatted as you want, and could run the operation from a button in the unshared workbook.

Or we can suggest CopyFromRecordset :) Although
"Trying to export with formatting replaces my existing spreadsheet rather than updating it."

Now I am confused.
Can you explain, in detail, what you are doing from where and post your code

gracie1972Author Commented:
I actually do not have any code or I would post it.  
So far all I do is run a macro (see attached picture).  

This macro exports data from a table to a specific tab within an open or closed workbook.  This process seems to work whether a user has the file open or not.

The issue is when it exports that data it loses the sort order from the table.  I

Is it better to write a function or code to do this?
@Nick, I'm not sure exactly what limitations there are in the shared workbook - I thought of CopyFromRecordset (honest, I did!) but hesitated to suggest it. I also just read some stuff on SO that suggested it didn't work in shared workbooks, but you may know better...
ImportExportSpreadsheet Macro Action
The name of the Access table to import spreadsheet data to, export spreadsheet data from, or link spreadsheet data to. You can also type the name of the Access select query you want to export data from.

Perhaps...ding, ding, ding ... we'll have a winner.
Your image doesn't show what you are exporting.
Is it a query or table?
If it is NOT a query, can you create a query with an Order By clause that will be the way you want the data sorted?
It looks like you can create a query that is
Select * from Stores Order By  and then whatever sort order you need.
One guesses
Select * from Stores Order By StoreName;
Save it as qryExportStores

In your macro, change Table from Stores to qryExportStores and have a go at it

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
> when I create a macro to export from the table it loses the sort order.

That's because a table has no sort order.
Create a query as Nick explains and export that.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.