Solved How to export Excel file to wanted directory?

sharonng

New member
Local time
Today, 19:30
Joined
Jul 7, 2021
Messages
11
My supervisor asked me that whether an access table can be exported to their wanted directory. Currently, I am using
Code:
outputFileName = CurrentProject.Path & "\Report002_" & tb_Year.Value & cmb_Quarter.Value & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "dbo_RP_SAMPLE_002", outputFileName, True
Application.FollowHyperlink outputFileName
MsgBox "Exported!", vbOKOnly
to export as an Excel file. I suppose it has to do with CurrentProject.Path but I just copied and pasted from a source so I don't really understand how it works. Will someone clarify it and tell me how to export to the wanted destination?
 
what you need is a FileDialog (you can google it).
and you need to add reference to
Microsoft Office XX.X Object Library.
 
Hi. Welcome to AWF!

What do you mean by "their wanted directory?" Is it a specific directory or do they want to pick it each time?
 
see this demo.
Hello, I have tried your code and it worked. However, that is not the case in my file. Compile error: User-defined type not defined appeared on the line Dim fd As Office.FileDialog. How to resolve it?
 
goto VBA (Alt-F11).
on the menu->Tools->Reference, add reference to:

Microsoft Office XX.X Object Library (XX.X is the version number you have).
 
goto VBA (Alt-F11).
on the menu->Tools->Reference, add reference to:

Microsoft Office XX.X Object Library (XX.X is the version number you have).
I cannot find the Reference option. Do I need to click something beforehand?
 
What do you see when you click on 'Tools'?
 
2021-07-08_15-20-00.png
2021-07-08_15-22-55.png
 
What do you see when you click on 'Tools'?
I see Macro, Access Options, Database1 Utilities, Digital Signature. (Sorry if there is not an exact match of the wordings - I translated them from another language.)
 
press Alt-F11 to go to VBA. you will find it there.
 
press Alt-Key + F11-Key (together) to go to VBA.
 
It is the 1st item, under Tool menu. Try it.
 

Users who are viewing this thread

Back
Top Bottom