Does anyone know if there is a snippet of code that automatically
removes the wrap text format in excel?
I have an access form that displays data and allows the user to click
on a cmdbutton to export the data to excel. However, every export
defaults to a formatted wrap text. I am trying to remove this default
if possible. Thanks in advance.
Here is my code:
Private Sub cmdADR_Excel_Click()
Dim strSQL As String
Dim dbDatabase As Database
Dim strQueryName As String
Dim intSQL As Integer
'Exports results to excel
If Len(txtCompoundSearch) < 1 Or IsNull(txtCompoundSearch) Then
MsgBox "Please run a search first."
Exit Sub
Else
strSQL = Trim(txtCompoundSearch)
strQueryName = "qryCompFreq_Excel"
Set dbDatabase = CurrentDb()
On Error Resume Next
dbDatabase.QueryDefs.Delete (strQueryName) 'Deletes the query
On Error GoTo 0
Set qdfResults = dbDatabase.CreateQueryDef(strQueryName, strSQL)
'creates new query
End If
On Error GoTo Err_cmdExport_Click
DoCmd.OutputTo acOutputQuery, "qryCompFreq_Excel", acFormatXLS,
"qryCompFreq_Excel" & ".xls", True
Exit_cmdExport_Click:
Exit Sub
Err_cmdExport_Click:
MsgBox Err.Description
Resume Exit_cmdExport_Click
End Sub