Solved

Open a .xls extention file using a command button

Posted on 2003-11-20
5
1,757 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mirrorEnds challenge 6 94
sumNumber challenge 16 111
tripleUp challenge 7 74
Not seen Link button 5 17
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

867 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

12 Experts available now in Live!

Get 1:1 Help Now