Solved

Open a .xls extention file using a command button

Posted on 2003-11-20
5
1,756 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
5 Comments
 
LVL 2

Accepted Solution

by:
MattWare earned 84 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 83 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 83 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Writing a parser for java language 4 61
java ^ examples 8 57
zeroFront challenge 7 71
mapAB Challlenge 35 89
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now