Results 1 to 4 of 4
  1. #1
    Eilleye is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    2

    access to excel help

    Hi,

    Thanks for taking the time to view this post.

    I need export an access query to an excel file which accomplished using the below code. The export will be posted on a SharePoint site for our customers to see, so i need to make it more "Pretty". Is there a way to customize the export (i.e. column height, row color, font etc) before it opens in excel?

    Thanks in advanced


    Private Sub Button_run_report_Click()
    On Error GoTo Button_run_report_Click_Err
    DoCmd.OutputTo acOutputQuery, "IDAS_help", "ExcelWorkbook(*.xlsx)", "", True, "", , acExportQualityPrint

    Button_run_report_Click_Exit:
    Exit Sub


    Button_run_report_Click_Err:
    MsgBox Error$
    Resume Button_run_report_Click_Exit
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You have more control over the output if you use automation, either to perform the export or to open the file after the export and manipulate it. Here's a primer:

    http://support.microsoft.com/kb/247412

    One trick I use when trying to figure out how to do something in automation is to record an Excel macro that performs the function, then examine/use that code in my Access code. It typically has to be tweaked, but gives you the guts of what you need.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Eilleye is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    2
    pbaldy, thanks for the reply.

    I record an Excel macro, but I am a VBA novice i have no clue how to get the code to work. can you help?

    Sub test()
    Cells.Select
    Selection.ClearFormats
    Columns("F:G").Select
    Range("G1").Activate
    Selection.NumberFormat = "m/d/yyyy"
    Range("A1").Select
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$I$135"), , xlYes).Name = _
    "Table1"
    Range("Table1[#All]").Select
    ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium2"
    Cells.Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Range("C7").Select
    Columns("C:C").EntireColumn.AutoFit
    Range("C8").Select
    ActiveWindow.SmallScroll Down:=-12

    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    If you review that link, in general what's needed from outside Excel is the Excel or Sheet object created in your automation code. For instance, in the link:

    oSheet.
    Range("A1").Value = "Last Name"

    or this from an app I have open:

    xl.Cells(50, 1).Select
    xl.Selection.Interior.ColorIndex = 8
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 04-25-2013, 03:47 PM
  2. excel link with access differs from simple export from access
    By M0RDANT in forum Import/Export Data
    Replies: 4
    Last Post: 03-25-2013, 02:43 PM
  3. Replies: 10
    Last Post: 12-28-2012, 02:06 PM
  4. Replies: 4
    Last Post: 12-17-2012, 01:21 PM
  5. Replies: 1
    Last Post: 08-31-2009, 10:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums