Solved

Visual basic 6 to excel application

Posted on 2001-09-11
5
283 Views
Last Modified: 2013-11-25
I wish to open an excel application from Visual basic 6.

I can create and save using the following code:
Private Sub Form_Load()
Dim obExcelApp As Object
Dim obWorkSheet As Object
Set obExcelApp = CreateObject("excel.Application")
obExcelApp.Workbooks.Add
Set obWorkSheet = obExcelApp.ActiveSheet
obWorkSheet.Cells(1, 1).Value = "Date"
obWorkSheet.Cells(1, 2).Value = "Num"
obWorkSheet.Cells(2, 1).Value = 21923.44
obWorkSheet.Cells(2, 2).Value = "April"
obExcelApp.Save ("C:\Donations1\Register.XLS")
End Sub

I wish to open the worksheet and edit it on screen.
0
Comment
Question by:JAwilson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6475064
Hi JAWilson, you want to show excel on the screen while editing in code ? then add one line with visible

Private Sub Form_Load()
Dim obExcelApp As Object
Dim obWorkSheet As Object
Set obExcelApp = CreateObject("excel.Application")
obExcelApp.Visible = True
obExcelApp.Workbooks.Add
Set obWorkSheet = obExcelApp.ActiveSheet
obWorkSheet.Cells(1, 1).Value = "Date"
obWorkSheet.Cells(1, 2).Value = "Num"
obWorkSheet.Cells(2, 1).Value = 21923.44
obWorkSheet.Cells(2, 2).Value = "April"
obExcelApp.Save ("C:\Donations1\Register.XLS")
End Sub

else let me know,

:O)Bruintje
0
 

Accepted Solution

by:
etienne14 earned 100 total points
ID: 6475074
If you really want to open and edit the worksheet try this

Shell "excel.exe c:\donations\register.xls",vbmaximizedfocus

regards
etienne14
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6478465
JAwilson, it is to your advantage to reject an answer immediately if it does not completely satisfy your requirements.

Lunchy
Friendly Neighbourhood Community Support Moderator
0
 

Expert Comment

by:hslow
ID: 6481501
hi,
you can open and edit yr excel file as below:

Option Explicit
Public appWorld As Excel.Application
Public wbWorld As Excel.Workbook


Sub OpenExcelFile()
On Error Resume Next 'ignore errors
    Set appWorld = GetObject(, "Excel.Application")
'look for a running copy of Excel
    If Err.Number <> 0 Then 'If Excel is not running then
      Set appWorld = CreateObject("Excel.Application")
     'run it
    End If
    Err.Clear   ' Clear Err object in case error occurred.
   
    On Error GoTo 0 'Resume normal error processing

    Set wbWorld = appWorld.Workbooks.Open("C:\Donations1\Register.XLS")
End Sub

Private Sub Form_Load()
Dim obWorkSheet As Excel.Worksheet

OpenExcelFile()
appWorld .Visible = True
appWorld .Workbooks.Add
Set obWorkSheet = appWorld.ActiveSheet
obWorkSheet.Cells(1, 1).Value = "Date"
obWorkSheet.Cells(1, 2).Value = "Num"
obWorkSheet.Cells(2, 1).Value = 21923.44
obWorkSheet.Cells(2, 2).Value = "April"
obExcelApp.Save ("C:\Donations1\Register.XLS")

End Sub

Hope this can help you :-)
Regards,
hslow
0
 

Author Comment

by:JAwilson
ID: 6515230
I used hslows comment to create the following code which works.
Private Sub Command5_Click()
Dim i As Integer
Dim j As Integer
Dim Numb1 As Integer
Dim Numb2 As Integer
Dim Numb3 As Integer
Dim obWorkSheet As Excel.Worksheet
OpenExcelFile
'obWorkSheet.Open ("c:\Donations1" & "\Register.XLS")
Set wbWorld = appWorld.Workbooks.Open("c:\Donations1" & "\Register1.XLS")
'Open("c:\donations1\register1.exl")
'OpenExcelFile
appWorld.Visible = True
'appWorld.Workbooks.Add
Set obWorkSheet = appWorld.ActiveSheet
obWorkSheet.Cells(1, 1).Value = "Date"
obWorkSheet.Cells(1, 2).Value = "Numb"
obWorkSheet.Cells(1, 3).Value = "DisbID"
'obWorkSheet.Cells(2, 1).Value = 9 / 11 / 1
obWorkSheet.Cells(1, 3).Value = "Account"
Dim DbDonations1 As New ADODB.Connection
Dim rsReceipts As New ADODB.Recordset
Dim rsDisbursements As New ADODB.Recordset
Dim rsTransfers As New ADODB.Recordset
Dim rsAssigned As New ADODB.Recordset
DbDonations1.Open "Donations1"
Set rsAssigned = rsReceipts
Data1.Recordset.MoveLast
Numb1 = Data1.Recordset("receiptID")
'MsgBox "Numb1= " & Numb1
For i = 1 To Numb1
Text3.Text = i
Set rsAssigned = DbDonations1.Execute("Select * From Receipts where receiptID = '" & Text3.Text & "'")
On Error GoTo Error_Fix
j = i + 1
obWorkSheet.Cells(j, 1).Value = rsAssigned("CreationDate"):
obWorkSheet.Cells(j, 2).Value = rsAssigned("AccountID"):
obWorkSheet.Cells(j, 3).Value = rsAssigned("Description")
Next
Set rsAssigned = rsDisbursements
Data3.Recordset.MoveLast
Numb2 = Data3.Recordset("DisbID")
'MsgBox "numb2 =" & Numb2
For i = 1 To Numb2
Text5.Text = i
Set rsAssigned = DbDonations1.Execute("Select * From Disbursements where DisbID = '" & Text5.Text & "'")
On Error GoTo Error_Fix
j = i + Numb1
obWorkSheet.Cells((j + 1), 1).Value = rsAssigned("CreateDate"):
obWorkSheet.Cells((j + 1), 2).Value = rsAssigned("AcctID"):
obWorkSheet.Cells((j + 1), 3).Value = rsAssigned("DisbID")
Next
Set rsAssigned = rsTransfers
Data4.Recordset.MoveLast
Numb3 = Data4.Recordset("TransferID")
'MsgBox "numb3 =" & Numb3
For i = 1 To Numb3
Text7.Text = i
Set rsAssigned = DbDonations1.Execute("Select * From Transfers where TransferID = '" & Text7.Text & "'")
On Error GoTo Error_Fix
j = i + (Numb1 + Numb2)
obWorkSheet.Cells((j + 1), 1).Value = rsAssigned("TransferDate"):
obWorkSheet.Cells((j + 1), 2).Value = rsAssigned("TransDescription"):
obWorkSheet.Cells((j + 1), 3).Value = rsAssigned("TransferID")
Next

Error_Fix:
Err.Clear
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question