Newbie question using Excel 
Author Message
 Newbie question using Excel

Here's one way to do it.  This method does not display the Excel
workbook, but does create an instance of it so you can manipulate it.
If you want to display Excel, you would need to declare and instantiate
an object variable of type Excel.Application and then call the method
to show Excel (I think it's Show, but not positive.)

You need to set a reference in your project to the Excel object
library:  Project\References\"Microsoft Excel x.x Object Library"
----------------------------------------------
Option Explicit

'Declare object variables for Excel workbook and worksheet objects
Private objWkBook As Workbook
Private objWkSheet As Worksheet

Private Sub Command1_Click()
    'manipulate the data on the worksheet
    MsgBox "The value in cell C5 is " & objWkSheet.Range("C5").Value
End Sub

Private Sub Form_Load()
    Dim strExcelFilePath As String
    strExcelFilePath = "D:\Documents and Settings\Administrator\My
Documents\Test.xls"

    'instantiate the workbook object by getting the workbook
    'from the Excel file
    Set objWkBook = GetObject(strExcelFilePath)

    'get the first worksheet from the workbook
    Set objWkSheet = objWkBook.Worksheets(1)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    'perform housekeeping - set object variables to nothing
    Set objWkSheet = Nothing
    Set objWkBook = Nothing
End Sub
--
Free audio & video emails, greeting cards and forums
Talkway - http://www.*-*-*.com/ - Talk more ways (sm)



Sun, 04 Aug 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Please assist a VB newbie with an easy Excel question

2. Newbie Excel 5.0 VB Macro Question

3. Newbie--Excel Macro question

4. Newbie VB4-Excel 5.0 question

5. newbie VB4-Excel 5.0 question

6. NEWBIE Question on Excel/VBA

7. Newbie question: How to export Outlook Express Block Senders list to Excel

8. newbie question: generating Excel spreadsheet from the web

9. Excel Worksheets...Newbie Question

10. Newbie question on a Form using Word 97

11. Newbie question using DBCombo control

12. Movement question (using theta) Newbie

 

 
Powered by phpBB® Forum Software