Formatting data exported to Excel (1 Viewer)

SBDatabases

New member
Local time
Today, 02:42
Joined
May 2, 2011
Messages
2
I'm using DoCmd.TransferSpreadsheet acExport to send data from a form to Excel and would like to be able to format the resulting spreadsheet, eg autofit columns, centre columns etc directly from Access.

This code does the basic job of creating a destination subfolder in the folder containing the database file and sending output data to replace anything already there.


Dim GetAppDir As String
Dim strDirPath As String
Dim strDB As String
Dim strDir As String
Dim strFilePath As String

strDir = "Trade\"
strDB = CurrentDb.Name
GetAppDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))
strDirPath = GetAppDir & strDir

If Len(Dir(strDirPath)) = 0 Then
On Error Resume Next
MkDir strDirPath
End If

strFilePath = strDirPath & "Trade.xlsx"

'If this file already exists, delete it
On Error Resume Next
Kill strFilePath

'Export current data to Excel
DoCmd.TransferSpreadsheet acExport, , "Trade", strFilePath

'View the spreadsheet
Shell "Explorer.exe /e, /root," & strFilePath, vbNormalFocus

Any suggestions?
 

Users who are viewing this thread

Top Bottom