Solved

Open a .xls extention file using a command button

Posted on 2003-11-20
5
1,763 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
[X]
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
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

Technology Partners: 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!

Question has a verified solution.

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

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…
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

729 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