?
Solved

Open a .xls extention file using a command button

Posted on 2003-11-20
5
Medium Priority
?
1,766 Views
Last Modified: 2007-12-19
I am trying to open an excel spreadsheet in an access data form. I want a form with a command button that when pressed, opens an existing file that is in an excel spreadsheet.

I tried to write the code in vb, but it wont work.

Can I do this?
 
0
Comment
Question by:katdude
3 Comments
 
LVL 2

Accepted Solution

by:
MattWare earned 336 total points
ID: 9790228
This is a great intro to automation.

http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/accessdev/html/odc_microsoftaccessoleautomation.asp

If this doesn't help, please submit the code you are trying to run with any errors you are getting.

Cheers,
Matt
0
 
LVL 2

Assisted Solution

by:incongruent
incongruent earned 332 total points
ID: 9791617
This is VBA code but it should still work...

-Allan

.....................................


On Error GoTo Err_Command59_Click
Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Application")


Set ExcelSheet = GetObject("C:\EXCEL.XLS")
ExcelSheet.Application.Visible = True
ExcelSheet.Parent.windows(1).Visible = True

Exit_Command59_Click:
    Exit Sub

Err_Command59_Click:
    MsgBox Err.Description
    Resume Exit_Command59_Click
0
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 332 total points
ID: 9792086
'Add a reference to Microsoft Excel 10 Object Library
'from menu Project>Reference

This is an example:
    Dim objExcel, objWB, objSheet As Object
    Dim objItem

On Error GoTo Err
    Set objExcel = New Excel.Application
    Set objWB = objExcel.Workbooks.open(App.Path & "\Analysis.xls")
    Set objSheet = objWB.Worksheets("YourWorkSheet)
   
    objSheet.cells(irow, icol) = "test data"   'irow and icol is the row/col you wish to change upon
       
    objWB.Save
    objWB.Close
    objExcel.Quit

    Set objSheet = Nothing
    Set objWB = Nothing
    Set objExcel = Nothing
   
    MsgBox "Data was entered into database", vbInformation
    Exit Sub
Err:
MsgBox "Error: " & Err.Description

~ fantasy ~
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 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