C
Carolyn Schmidt
Hi,
Here's how I did what you are trying to do, but I used the
RunCommand instead of TransferSpreadsheet.
Hope this helps.
Dim XlObj1 As Excel.Application
Dim strQN As String
Dim MyDB As Database
DoCmd.SetWarnings False
Set MyDB = CurrentDb()
Set XlObj1 = New Excel.Application
XlObj1.Workbooks.Add
strQN = "qry6-SelectAllData"
DoCmd.OpenQuery strQN
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy
XlObj1.ActiveSheet.Paste
With XlObj1
.Worksheets("Sheet1").Activate
.ActiveSheet.Name = "USDA Data"
.ActiveSheet.Columns("A").ColumnWidth = 10
.ActiveSheet.Columns("B").ColumnWidth = 10
.ActiveSheet.Columns("C").ColumnWidth = 10
.ActiveSheet.Columns("D").ColumnWidth = 10
.ActiveSheet.Columns("E").ColumnWidth = 10
.ActiveSheet.Columns("F").ColumnWidth = 21
.ActiveSheet.Columns("G").ColumnWidth = 16
.ActiveSheet.Columns("H").ColumnWidth = 10
End With
When done, you just have to close the query, close and
save the Excel object, etc.
Carolyn
want to do is format the Excel file i.e. bold row 1, wrap
the text in Columns N and O, etc.
Here's how I did what you are trying to do, but I used the
RunCommand instead of TransferSpreadsheet.
Hope this helps.
Dim XlObj1 As Excel.Application
Dim strQN As String
Dim MyDB As Database
DoCmd.SetWarnings False
Set MyDB = CurrentDb()
Set XlObj1 = New Excel.Application
XlObj1.Workbooks.Add
strQN = "qry6-SelectAllData"
DoCmd.OpenQuery strQN
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdCopy
XlObj1.ActiveSheet.Paste
With XlObj1
.Worksheets("Sheet1").Activate
.ActiveSheet.Name = "USDA Data"
.ActiveSheet.Columns("A").ColumnWidth = 10
.ActiveSheet.Columns("B").ColumnWidth = 10
.ActiveSheet.Columns("C").ColumnWidth = 10
.ActiveSheet.Columns("D").ColumnWidth = 10
.ActiveSheet.Columns("E").ColumnWidth = 10
.ActiveSheet.Columns("F").ColumnWidth = 21
.ActiveSheet.Columns("G").ColumnWidth = 16
.ActiveSheet.Columns("H").ColumnWidth = 10
End With
When done, you just have to close the query, close and
save the Excel object, etc.
Carolyn
create an Excel file from the results of a query. What I-----Original Message-----
I'm using the TransferSpreadsheet of the DoCmd object to
want to do is format the Excel file i.e. bold row 1, wrap
the text in Columns N and O, etc.
the Excel file, or (2) do the formatting on my own?Any suggestions on how to either (1) attach a template to