Results 1 to 2 of 2
  1. #1
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83

    Access to Excel template

    Can't seem to find a solution to this one-
    I have an Excel 2007 workbook with 4 existing sheets that each have a pivot table built off of them.
    Single Access (2007) crosstab query that I am filtering from the form (in query Forms!frmMain!cboType) based on 1 of 4 selections corresponding to each Excel sheet.
    I would like to export the filtered query results to each of the 4 worksheets, retaining the existing headers in the worksheet.

    I have tried using this VBA that I found that is supposed to export the filtered query to a new sheet (DSG_BOP_Rsvd), then copy/paste into the the correct sheet (Rsvd_Date). This seems to have deleted my file for some reason.

    Private Sub cmdAvailable_Click()
    On Error GoTo Err_cmdAvailable_Click
    Dim stDocName As String
    stDocName = "DSG_BOP_Rsvd"

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, stDocName, "\\filelocation\PINN_Template.xls", True
    Set xlObj = GetObject("\\filelocation\PINN_Template.xls")
    With xlObj.Application
    .Sheets("DSG_BOP_Rsvd").Select
    .Range("A:BG").Select
    .Selection.Copy


    .Sheets("Rsvd Data").Select
    .Range("A1").Select
    .ActiveSheet.Paste
    End With
    ' DoCmd.OpenQuery stDocName, acNormal, acEdit
    Exit_cmdAvailable_Click:
    Exit Sub
    Err_cmdAvailable_Click:
    MsgBox Err.Description
    Resume Exit_cmdAvailable_Click

    End Sub

    I've looked at hundreds of posts but can't seem to find something that will work in my situation. Could anyone please tell me if I am on the right track with this code and if I just need to tweak it to get it to work?

    Thank you!

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I've looked at hundreds of posts but can't seem to find something that will work in my situation. Could anyone please tell me if I am on the right track with this code and if I just need to tweak it to get it to work?

    Thank you!

    If has been a long while since I have imported/exported between Excel and Access. I found this site - maybe it will help.

    http://www.accessmvp.com/kdsnell/EXCEL_Export.htm

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

Similar Threads

  1. Export table to excel using excel template
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 1
    Last Post: 06-27-2011, 02:10 AM
  2. Access SOP template
    By daveISWS in forum Access
    Replies: 1
    Last Post: 12-02-2010, 05:06 AM
  3. MS Access Template Problem
    By Zan in forum Access
    Replies: 8
    Last Post: 12-01-2010, 10:16 PM
  4. Import Excel file as report template - possible?
    By justinwright in forum Reports
    Replies: 2
    Last Post: 11-01-2010, 07:01 AM
  5. Exporting to a custom Excel template
    By theronlightfoot in forum Import/Export Data
    Replies: 2
    Last Post: 04-12-2010, 11:51 PM

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