Results 1 to 3 of 3
  1. #1
    ketangarg86 is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2014
    Posts
    24

    Access VBA - transfer data to multiple excel sheets and format them

    Hi,

    I have some questions. Could you please help.

    1. I am using the below to transfer data from Access query to multiple worksheets in the same excel workbook (xlsx) which is working fine. But the name in the excel workbook comes as _1_Opportunity__Focus_ and _1a_Opportunity__Non_focus_ instead of 1-Opportunity (Focus) and 1a-Opportunity (Non-focus). Please help.

    DoCmd.TransferSpreadsheet acExport, , "Stage 1", FolderSelection, True, "1-Opportunity (Focus)"
    DoCmd.TransferSpreadsheet acExport, , "Stage 1a", FolderSelection, True, "1a-Opportunity (Non-focus)"



    2. Can I transfer data from access to a .xlsm excel file. What would be command then.

    3. Once I have transferred the data to the excel file, I want to format the excel file from within the same access vba which I used to transfer the data. I can record the macro in another excel file and copy the code to the macro but having difficulty how to do that.

    Please help.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    You cant have spaces in tab name. Name cant start with a number.

    To 'edit' excel files you need to start a session to control by vba.
    REMEMBER TO ADD EXCEL.OBJECT LIBRARY in vbe menu, TOOLS, REFERENCES.

    Code:
    Private Sub EditXL()
    Dim xl As excel.Application
    Dim sSht As String
    Dim colSheets As New Collection
    Set xl = CreateObject("excel.application")
    With xl
       .Visible = True
       .Workbooks.Open pvFile
        
               'record macro in Excel and put here.. remember to put dot in from of xl objects
           .activeworksheet.select
       .ActiveWorkbook.Close False
       .Quit
    End With
    Set xl = Nothing
    end sub

  3. #3
    ketangarg86 is offline Novice
    Windows 8 Access 2013
    Join Date
    Sep 2014
    Posts
    24
    Thanks dude. I am getting an error at the below. I put dot in front of xl object. I tried even removing the dot from in front of columns but still the same error. I am using Access 2013. Could you please help.

    .Sheets("1-Opportunity (Focus)").Activate
    .Columns("I:I").ColumnWidth = "26"

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

Similar Threads

  1. Replies: 2
    Last Post: 10-15-2014, 12:30 PM
  2. Replies: 4
    Last Post: 07-29-2014, 06:18 AM
  3. Replies: 12
    Last Post: 12-17-2012, 12:47 PM
  4. Replies: 1
    Last Post: 08-25-2012, 06:11 PM
  5. Combine multiple Excel sheets in Access
    By Adcock1969 in forum Access
    Replies: 17
    Last Post: 09-07-2011, 06:03 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