|
#1
|
|||
|
|||
|
VB code to export data to Excel
I have placed a command button on my form in MS Access to export specific data to populate specific cells in Excel. I won't be pulling ALL the data from my main table, just specific fields, and auto-populating specific cells in an Excel document (template) that I have created.
I don't know how to write code at all, but I found this on the web: Code:
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Set appExcel = GetObject("Excel.Application")
Set wbk = appExcel.Workbook.Open("L:\Bper Spec\Cione\TEST\TEST (RSA).xls", , True)
Set wks = wbk.Worksheet("RSA")
With xlSheet
.Cells(1, 1).Value = "I am in Row 1, Column A"
.Cells(3, 3).Value = "I am in Row 3, Column C"
'and so on, filling in the cells
End With
I've researched and researched to find a solution, but no dice. Any help would be appreciated. |
|
#2
|
|||
|
|||
|
with xlSheet should be with wks
|
|
#3
|
|||
|
|||
|
Tried it; got a runtime error.
|
|
#4
|
|||
|
|||
|
Changes in red - New code should look like this:
Code:
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Set appExcel = GetObject("Excel.Application")
Set wbk = appExcel.Workbooks.Open("L:\Bper Spec\Cione\TEST\TEST (RSA).xls", , True)
Set wks = wbk.Worksheets("RSA")
With wks
.Cells(1, 1).Value = "I am in Row 1, Column A"
.Cells(3, 3).Value = "I am in Row 3, Column C"
'and so on, filling in the cells
End With
Code:
Set wbk = appExcel.Workbooks.Open("L:\Bper Spec\Cione\TEST\TEST (RSA).xls", , True)
|
|
#5
|
||||
|
||||
|
Ron's code will probably solve your problem for this, but I would suggest that in the future if something like this (an error) occurs that you specify what the error number is and what the error verbage is.
There are only about a zillion differnent error possibilities. Telling us specifically which error you are getting helps enormously. ![]() Thanks.
__________________
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section. ![]() Please use [Code]your code goes in here[/Code] tags when posting code. Before posting your question, did you look here? Got a question on Linux? Visit our Linux sister site. Modifications Required For VB6 Apps To Work On Vista ![]() Microsoft MVP 2005/2006/2007/2008/2009 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Scan ip mapping and fill correct data that have country code | Mark107 | .NET | 5 | 07-21-2008 10:41 PM |
| Pls help me in How to import Excel data into Ms Access suing VB code | P.Gopi Chand | VB Classic | 2 | 12-27-2006 11:43 PM |
| Microsoft's C++ bigotry | Phil Weber | .NET | 632 | 10-01-2003 01:00 AM |
| Need to reduce network trips and speed up ADO VB code!! | Richard Lloyd | VB Classic | 8 | 06-22-2001 05:52 AM |
| Bad programming practices encouraged.... namely VB! | b.a.h. | .NET | 90 | 04-17-2001 01:45 AM |