Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Export recordset from Access to Excel

Status
Not open for further replies.

deadfish

Programmer
Nov 13, 2002
50
0
0
HK
Hi,

I would like to export data from a Access Table to Excel. I do try some code to export the data, but I can't open the Excel file immediately for user to preview. How to let the user to view the Excel file immediately after exporting the data? Can I specified the starting cell and worksheet of the Excel also?

Could anyone tell me how to acheive this? Thanks a lot!

 
Try this, I hope it will help you:

Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As Long) As Long

Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Sub CloseExcel()
Dim MyXL As Object
DetectExcel
Set MyXL = GetObject("C:\Path\Filename.xls")
MyXL.Open 'Maybe it's what you need, I hope
MyXL.Save
MyXL.Close
End Sub

Sub DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
ExcelNotOpen = 1
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top