megatronixs
Registered User.
- Local time
- Today, 17:27
- Joined
- Aug 17, 2012
- Messages
- 719
Hi all,
I have tried without luck to paste a recordset into excel in one sheet and then moving it out from there (cuting) and paste it to a second sheet.
The main idea is to use the query results to an excel sheet, then activate the excel sheet, cut it from there and move it to the second sheet. For now I managed to cut it off, but I'm not able to paste it to the second sheet.
The steps I wanted was to create a excel workbook, open it, paste the recordset into it, cut it and move it to the sheet 2 (needs to be created first). The main loop in the access database will go to the next query output and then activate the workbook again, paste the recordset, cut it off and then move it to the sheet2 (I will use some code to find the last column to past it there).
So far I have the below code:
It seems something easy, but I just don't get it working.
I posted it on this site also when I had the first try, but for some strange reason my IP address got blocked and I can't use the forum anymore :-(
http://www.accessforums.net/modules/using-loop-get-content-table-4-fields-56611/index2.html
Greetings.
I have tried without luck to paste a recordset into excel in one sheet and then moving it out from there (cuting) and paste it to a second sheet.
The main idea is to use the query results to an excel sheet, then activate the excel sheet, cut it from there and move it to the second sheet. For now I managed to cut it off, but I'm not able to paste it to the second sheet.
The steps I wanted was to create a excel workbook, open it, paste the recordset into it, cut it and move it to the sheet 2 (needs to be created first). The main loop in the access database will go to the next query output and then activate the workbook again, paste the recordset, cut it off and then move it to the sheet2 (I will use some code to find the last column to past it there).
So far I have the below code:
Code:
Private Sub query_results()
Dim sFile As String
Dim stDocName As String
Dim i As Integer
Dim FinalRow As Long
Dim xlApp As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)
xlApp.Visible = True
Worksheets.Add
FinalRow = Cells(Rows.Count, 2).End(xlUp).Row
sFile = "C:\Query\QueryResults.xls"
stDocName = "Query_Run1"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Query_Run1", ":\Query\QueryResults.xls"
Range("A1:G" & FinalRow).Cut
Range("A1").Select
With Selection
Cells(1, 1).PasteSpecial
End With
End Sub
It seems something easy, but I just don't get it working.
I posted it on this site also when I had the first try, but for some strange reason my IP address got blocked and I can't use the forum anymore :-(
http://www.accessforums.net/modules/using-loop-get-content-table-4-fields-56611/index2.html
Greetings.