Results 1 to 3 of 3

Thread: Excel

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    51

    Question Excel

    Can i export data from a file to a template in excel?


  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    You can import data from a file using a template in Excel, then save this with all of the template's formatting etc intact - this could be one way to achieve what you're looking for...

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Here's one quick example, this opens up excel & then opens a saved template file. Data is copied in (this one is just copying in data from a recordset assumed to be already opened & populated), and the file - with the formatting and data is then saved as a standard *.xls file to a separate folder - should be the type of thing you're after...
    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     Dim objXLApp As Excel.Application
    3.     Set objXLApp = New Excel.Application
    4.  
    5.     With objXLApp
    6.         .Workbooks.Open "C:\Path\TemplateFile.xlt"
    7.        
    8.         .Workbooks(1).Sheets("Sheet1").Range("A1").CopyFromRecordset RecordsetVariable
    9.        
    10.         .Workbooks(1).SaveAs "C:\Path2\StandardExcelFormatFile.xls"
    11.         .Workbooks(1).Close
    12.        
    13.         .Quit
    14.     End With
    15.    
    16.     Set objXLApp = Nothing
    17. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width