Excel Template

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
-----Original Message-----
I'm using the TransferSpreadsheet of the DoCmd object to
create an Excel file from the results of a query. What I
want to do is format the Excel file i.e. bold row 1, wrap
the text in Columns N and O, etc.
Any suggestions on how to either (1) attach a template to
the Excel file, or (2) do the formatting on my own?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top