Solved

How do I adjust excel column widths when exporting from Access with DoCmd.OutputTo

Posted on 2008-10-12
2
402 Views
Last Modified: 2013-11-27
Hi I am using the following code to export an excel spreadsheet from Access.

DoCmd.OutputTo acOutputQuery, "qry_export", acFormatXLS, rs!state_FK & "-" & rs!Declaration & " Loan Closing " & DatePart("m", dteReport) & "-" & DatePart("d", dteReport) & "-" & DatePart("yyyy", dteReport) & " .xls"

What vba code do I use to make the second column ("B") export with the autofit option so the cell contents aren't truncated?
0
Comment
Question by:BradleyOnTheRoad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 22699686
Since you need to automate Excel to do the column width, I'd just do this:

Dim xlApp As Object, xlWb As Object
Dim rsOut As DAO.Recordset

Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
With xlWb
    Set rsOut = CurrentDb.OpenRecordset("qry_export")
    With .Worksheets(1)
        .[a1].CopyFromRecordset rsOut
        .Columns(2).AutoFit
    End With
    .SaveAs rs!state_FK & "-" & rs!Declaration & " Loan Closing " & Format(dteReport, "yyyy-mm-dd") & ".xls"
    .Close False
End With

Set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing
0
 

Author Closing Comment

by:BradleyOnTheRoad
ID: 31505514
Thanks. That'll do the trick.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question