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!

Launching Excel from a VB6 app 2

Status
Not open for further replies.

malthouse

Programmer
Sep 27, 2003
1
0
0
GB
Hi. I want to shell out a report created in my VB6 app into Excel (via an "export to Excel" icon in my VB6 app).
For example, report name is rptStaffGrades. User should be able to click on an Excel icon in my VB6 app, which launches Excel and shows rptStaffGrade.xls, which is the data from the report exported into an Excel spreadsheet.

Does anyone know of any controls that handle this, or how to achieve it in my VB6 app?

Thanks.
 
Hi Malthouse,
Your question is quite clear.
You can add an OLE control to the VB 6.0 form and there comes a pop up dialog box,in which you select the create new file radio button then give the path in which you have the excel,say,C:\ProgramFiles\MSOffice\Excel

Now you will be seeing the Excel icon in your OLE with the name excel.exe below.

You type the codes for populating the excel sheet in the OLE_Click event now.

Hope it will work for you.

For more details give your precise requirement,so that i can send you codes.

With Regards,
D.Paramesh
 
this example will open an existing xls file and write data on it and saves it as another xls file so the original will never be modified

On Error GoTo excel_er
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Open("XLS path ")
Set oSheet = oBook.Worksheets(1)
'headings
oSheet.range("A1").Value = "Name"
oSheet.range("A2").Value = "Telephone:"

'data
oSheet.range("B1").Value = "John"
oSheet.range("B2").Value = "777-777-7777"


oBook.SaveAs "file.XLS"
oExcel.Visible = True
'oExcel.Quit

Exit Sub
excel_er:
MsgBox "Excel is not installed or .XLS file cant be found"
Exit Sub


I hope this work for you, forme works greate

Angel
 
If u are using Crystal Report then it has builtin Button to export to many format i.e. Email , Excel etc.

regards

KQKMBI

 
That brill, how can I create the excel file from scratch? Aposed to having one copied?

[red]
Thankyou[/red]
Matt
 
You could always try ShellExecute:

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Dim res As Long

Private Sub mnuViewExcel_Click()
res = ShellExecute(hwnd, vbNullString, "EXCEL FILE NAME", vbNullString, vbNullString, vbNormalFocus)
If res = 31 Then
MsgBox "This file is not associated with a program!", vbCritical, "File Association Error"
Exit Sub
End If
End Sub

Swi
 
> That brill, how can I create the excel file from scratch? Aposed to having one copied?

Dim objXlApp As Excel.Application
Dim objXlBook As Excel.Workbook

Set objXlApp = New Excel.Application
Set objXlBook = objXlApp.Workbooks.Add


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top