Following is an example of Code to Open Excel, and populate a particular template. You can actually select which file, sheets and cells to populate via VBA. This works well if you have a template that you want to fill in and save as a .xls file. That way you keep all the formatting of the template. <br><br>The code is lengthy, just paste the whole thing into a blank module, and then it will be easier to read (especially the comments). Obviously, this was designed to be used with the tables and data in my database, so you will have to modify it completely to work for you. This is just a sample of what is possible with VBA. If you need clarification, let me know.<br><br>==========<br>' Constants<br>Private Const XLS_LOCATION As String = "C:\My Documents\Spreadsheets\Vault.xlt"<br>Private Const XLT_LOCATION As String = "C:\Windows\Vault.xlt"<br>Private Const MC_START_ROW As Integer = 299<br>Private Const MC_END_ROW As Integer = 100<br>Private Const VISA_START_ROW As Integer = 999<br>Private Const VISA_END_ROW As Integer = 800<br><br>Public Sub PopulateExcel()<br>On Error GoTo Populate_Err<br> Dim db As Database<br> Dim rs As Recordset<br> Dim objXL As Object, objSheet As Object, objRange As Object<br> Dim strSaveAs As String, strVISA As String, strMC As String<br> Dim x As Integer, intRow As Integer<br> <br> DoCmd.Hourglass True<br> Set db = CurrentDb()<br> <br> ' Set the SQL strings for the two recordsets that will be opened<br> strVISA = "SELECT [Card Style], [Start Inventory] FROM [qryworking inventory start] WHERE [Plastic Type] = 'VISA'"<br> strMC = "SELECT [Card Style], [Start Inventory] FROM [qryworking inventory start] WHERE [Plastic Type] = 'MC'"<br> <br> ' Open, and make visible the Excel Template (Vault.xlt) which resides on the desktop<br> Set objXL = GetObject(XLT_LOCATION)<br> objXL.Application.Visible = True<br> objXL.Parent.Windows(1).Visible = True<br> <br> ' Open the VISA recordset, and activate the VISA sheet in the template<br> Set rs = db.OpenRecordset(strVISA, dbOpenSnapshot)<br> Set objSheet = objXL.worksheets("Visa"

<br> objSheet.Activate<br> rs.MoveFirst<br> x = 4<br> <br> ' Insert the data from the VISA recordset into the VISA worksheet<br> Do Until rs.EOF<br> objXL.activesheet.cells(x, 1).Value = rs![Card Style]<br> objXL.activesheet.cells(x, 2).Value = rs![Start Inventory]<br> x = x + 1<br> rs.MoveNext<br> Loop<br> <br> ' Delete all unnecessary rows making the VISA worksheet only as long as it needs to be<br> intRow = VISA_START_ROW<br> With objSheet<br> .select<br> Do Until intRow = VISA_END_ROW<br> If .Range("A" & intRow).Value = "" Then<br> Set objRange = .Range("A" & intRow & ":B" & intRow & ":C" & intRow & "

" & intRow & ":E" & intRow _<br> & ":F" & intRow & ":G" & intRow & ":H" & intRow & ":I" & intRow & ":J" & intRow _<br> & ":K" & intRow & ":L" & intRow & ":M" & intRow & ":N" & intRow & ":O" & intRow & "

" & intRow)<br> objRange.Delete 'Shift:=objXLUp<br> End If<br> intRow = intRow - 1<br> Loop<br> End With<br> rs.CLOSE<br> <br> ' Open the MC recordset, and activate the MC sheet in the template<br> Set rs = db.OpenRecordset(strMC, dbOpenSnapshot)<br> Set objSheet = objXL.worksheets("MC"

<br> objSheet.Activate<br> rs.MoveFirst<br> x = 4<br> <br> ' Insert the data from the MC recordset into the MC worksheet<br> Do Until rs.EOF<br> objXL.activesheet.cells(x, 1).Value = rs![Card Style]<br> objXL.activesheet.cells(x, 2).Value = rs![Start Inventory]<br> x = x + 1<br> rs.MoveNext<br> Loop<br> <br> ' Delete all unnecessary rows making the MC worksheet only as long as it needs to be<br> intRow = MC_START_ROW<br> With objSheet<br> .select<br> Do Until intRow = MC_END_ROW<br> If .Range("A" & intRow).Value = "" Then<br> Set objRange = .Range("A" & intRow & ":B" & intRow & ":C" & intRow & "

" & intRow & ":E" & intRow _<br> & ":F" & intRow & ":G" & intRow & ":H" & intRow & ":I" & intRow & ":J" & intRow _<br> & ":K" & intRow & ":L" & intRow & ":M" & intRow & ":N" & intRow & ":O" & intRow & "

" & intRow)<br> objRange.Delete<br> End If<br> intRow = intRow - 1<br> Loop<br> End With<br> <br> ' Calculate totals on spreadsheet<br> objXL.Application.calculate<br> <br> ' Set the save string, and save the spreadsheet<br> strSaveAs = "C:\Windows\Desktop\" & Format(DATE, "mmddyyyy"

& ".xls"<br> objXL.SaveCopyAs strSaveAs<br><br> ' Quit Excel<br> objXL.Application.displayalerts = False<br> objXL.Application.Quit<br> <br> Set objXL = Nothing<br> Set objSheet = Nothing<br> Set objRange = Nothing<br> Set rs = Nothing<br><br>Populate_Exit:<br> DoCmd.Hourglass False<br> Exit Sub<br> <br>Populate_Err:<br> MsgBox Err.Number & ": " & Err.Description<br> GoTo Populate_Exit<br>End Sub<br>========== <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href=
Application Development