using the excel sheet in a VB form

Posted on 2001-07-24
Last Modified: 2012-06-21
I am trying to use the excel sheet in a vb form to keep the program clean.  When I added the sheet to the form it's default name is 'Sheet1'.  I want to be able to populate the sheet from a access DB and allow the user to make changes and then save data back to DB.  I'm having problems referencing the cells.  Can anyone show me the code on how to reference the 'Sheet1' so I can control the cells?
Question by:jayhogan
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
  • 4
  • 3

Expert Comment

ID: 6312923
Here is an example

Private Sub cmdButtonSum_Click()

   Dim Obj1 As Object
   Dim answer As Integer
        Set Obj1 = CreateObject("Excel.Application")
        Obj1.Visible = True
        Obj1.Cells(1, 1).Value = textbox1.Text
        Obj1.Cells(2, 1).Value = textbox2.Text
        Obj1.Cells(3, 1).Formula = "=R1C1+R2C1"
        answer = Obj1.Cells(3, 1)
        MsgBox (answer)
        Set Obj1 = Nothing

End Sub


Expert Comment

ID: 6313202
Hi jayhogan.

Try this :

Private Sub Command1_Click()
Dim xlApp As New Excel.Application
Dim xlWb As New Excel.Workbook
Dim xlSht As Excel.Sheets

   Set xlApp = CreateObject("Excel.Application")
   xlApp.Visible = True
   Set xlWb = xlApp.Workbooks.Add
   Set xlSht = xlWb.Sheets
   xlSht(1).Cells(1, 1) = "Test"
   MsgBox xlSht(1).Name
   Set xlSht = Nothing
   Set xlWb = Nothing
   Set xlApp = Nothing
End Sub

Author Comment

ID: 6313475
these 2 routines work but they still open excel outside of vb.  What I've added is under Project - Componets - Insertable Objects - and then Microsoft Excel Worksheet.  Adding this allows me to create a sheet on a form.  That's the one I'm trying to edit.
Industry Leaders: 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!


Accepted Solution

Dave_Greene earned 100 total points
ID: 6313482
Just get rid of  "Set Obj1 = CreateObject("Excel.Application")"

Use Obj1 or whatever your control name is on the form  


Author Comment

ID: 6314047
when i try to run


i get an error 'Method or Data Member not found

Expert Comment

ID: 6314056
looks like you are bypassing your excel object and coding right to the sheet level.  


Author Comment

ID: 6314081
I figured it out. my line must read

frmAddTags.Sheet1.Object.Worksheets("Sheet1").Cells(1, 1) = "????"

I'm going to accept your answer because you did get me going towards the right direction. thanks

Author Comment

ID: 6314085
I figured it out. my line must read

frmAddTags.Sheet1.Object.Worksheets("Sheet1").Cells(1, 1) = "????"

I'm going to accept your answer because you did get me going towards the right direction. thanks

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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