Write To Existing Excel File

H

H_Odish

Trying to write from a table in Access directly to an existing Excel file.
Cant use MSQuery, and dont want to do TransferData, want to write directly.
Can create a blank file and write to that page, but dont know how to write
code in Access to call the existing file as the one to write to. Any help
would be greatly appreciated.

Thanks-
 
G

Guest

hi,
Try something like this
Opens a specific excel workbook with VBA
Public Sub TestMacroRun()
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Set xlx = CreateObject("Excel.Application")
xlx.Visible = True
Set xlw = xlx.workbooks.Open("C:\Filename.xls")
Set xls = xlw.Worksheets("WorksheetName")
Set xlc = xls.Range("A1")
' put code here to write into the cells etc.
' .
' .
' .
Set xlc = Nothing
Set xls = Nothing
xlw.Save
xlw.Close False
Set xlw = Nothing
xlx.Quit
Set xlx = Nothing
End Sub

regards
FSt1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top