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
Solved

Open a .xls extention file using a command button

Posted on 2003-11-20
5
1,761 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

856 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