Results 1 to 4 of 4
  1. #1
    niloufar is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    24

    I need to export table to excel template and save as different name

    I have looked everywhere and since I don't know alot about VBA I don't really know after exporting into my file how TO save my template to different name.




    Please help me.


    here is my Code:


    Code:
    With myRecordset
              Do Until .EOF
              
              'join report table with my request table's Rows
              'Create newworksheet for each report joint with requestTable rows
                    Set qdf = dbsReport.CreateQueryDef("Template", _
                    " do some join")
                    
                    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "TempFile", xlsxTempPath, True, SHEETNAME
    
    
    
    
                    Here I would Like to Save this workbook to different name, Plzzz...
    
    
    
    
                    DoCmd.DeleteObject acQuery, "Template"
                    
              
           
              Loop
           End With

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862

  3. #3
    niloufar is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    24

    Updated saveAs code, now i get error

    I have looked everywhere and since I don't know alot about VBA I don't really know after exporting into my file how TO save my template to different names in each loop and after creating first file it will errors for the second loop."Run-time error'91': object var or with block var not set" What is that? how can be fixed?


    Please help me.


    here is my Code:


    Code:
         With myRecordset
                  Do Until .EOF
                  
                  'join report table with my request table's Rows
                  'Create newworksheet for each report joint with requestTable rows
                        Set qdf = dbsReport.CreateQueryDef("Temp", _
                        " do some join")
                            
        
        xlsxSheet = rs.Fields("[Name]")
                        
                        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Temp", xlsxPath, True, "FlatFile"
                        
                        Set objXL = New Excel.Application
                        Set objWkb = objXL.Workbooks.Open(xlsxPath)
                        
                        objXL.Visible = False
                        ActiveWorkbook.SaveAs Filename:=SaveAsPath & xlsxSheet & ".xlsx", FileFormat:=51, CreateBackup:=False
                        objWkb.Close
                        Set objWkb = Nothing
                        objXL.Quit
                        Set objXL = Nothing
                                       
        
                        DoCmd.DeleteObject acQuery, "Temp"
                        
               
                  Loop
               End With
    Last edited by niloufar; 07-30-2014 at 11:35 PM. Reason: improved my code

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    If you want to loop recordset, need .MoveNext in the loop. Otherwise the loop is reading the same record over and over and would be an endless loop. However, something is triggering error so you are not yet experiencing the endless loop. Maybe saving the file to the same file name again is causing the break. What line triggers the error?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 5
    Last Post: 02-03-2014, 03:06 AM
  2. Replies: 1
    Last Post: 10-28-2013, 12:32 PM
  3. Export Queries to Excel tabs with Save as Dialog box
    By deepanadhi in forum Import/Export Data
    Replies: 1
    Last Post: 05-16-2012, 10:36 AM
  4. Export table to excel using excel template
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 1
    Last Post: 06-27-2011, 02:10 AM
  5. Replies: 1
    Last Post: 04-17-2011, 04:16 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