PC Review


Reply
Thread Tools Rate Thread

how to access data from excel to/from another program using Vb

 
 
Abel
Guest
Posts: n/a
 
      16th Mar 2009
Do you have a code sample?
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      16th Mar 2009
Dear Abel

Try below code after referencing Microsoft Excel Object Library

If this post helps click Yes
---------------
Jacob Skaria


Dim xlApp As Excel.Application
Dim xlWB1 As Excel.Workbook

Set xlWB1 = xlApp.OpenWorkbook("c:\temp.xls")
'Read values
strTemp = xlWB1.Sheets(1).Range("A1")
xlWB1.Close
Set xlWB1 = Nothing

xlApp.Quit
Set xlApp = Nothing


 
Reply With Quote
 
Doug Robbins - Word MVP on news.microsoft.com
Guest
Posts: n/a
 
      16th Mar 2009
To use that code, you will need to set a reference to the Excel Object
Library.

See the article "Control Excel from Word" at:

http://www.word.mvps.org/FAQs/InterD...XLFromWord.htm

and the article "Early vs. Late Binding" at:

http://www.word.mvps.org/FAQs/InterD...ateBinding.htm




--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Jacob Skaria" <(E-Mail Removed)> wrote in message
news:2C194C86-6EA0-4B75-894C-(E-Mail Removed)...
> Dear Abel
>
> Try below code after referencing Microsoft Excel Object Library
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> Dim xlApp As Excel.Application
> Dim xlWB1 As Excel.Workbook
>
> Set xlWB1 = xlApp.OpenWorkbook("c:\temp.xls")
> 'Read values
> strTemp = xlWB1.Sheets(1).Range("A1")
> xlWB1.Close
> Set xlWB1 = Nothing
>
> xlApp.Quit
> Set xlApp = Nothing
>
>



 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      16th Mar 2009
Let's say you are in Access, for instance, and you want to control Excel.
Follow the logic below:
It is quite easy to perform operations in Excel, and control the entire
process from Access. Make sure you set a reference to Excel, and then run
this code in an Access module:
Option Compare Database

Option Explicit ' Use this to make sure your variables are defined

' One way to be able to use these objects throughout the Module is to
Declare them here, and not in a Sub
Private objExcel As Excel.Application
Private xlWB As Excel.Workbook
Private xlWS As Excel.Worksheet

Sub Rep()
Dim strFile As String

strFile = "C:\filename.xls"

' Of course, this is just an example; put the actual path to your actual
file here…

' Opens Excel and makes it Visible

Set objExcel = New Excel.Application

objExcel.Visible = True

' Opens up a Workbook

Set xlWB = objExcel.Workbooks.Open(strFile)

' Sets the Workseet to the last active sheet - Better to use the commented
version and use the name of the sheet.

Set xlWS = xlWB.ActiveSheet

' Set xlWS = xlWB("Sheet1")

With xlWS ' You are now working with the Named file and the named worksheet

' Your Excel code begins here…you can even record a macro and make the
process super easy!!

End With

' Close and Cleanup

xlWB.SaveAs xlSaveFile
xlWB.Close
xlapp.Quit

Set xlapp = Nothing

End Sub

Send me an email if you have any questions about controlling Excel from
Access!!

Regards,
Ryan---


--
RyGuy


"Doug Robbins - Word MVP on news.microsof" wrote:

> To use that code, you will need to set a reference to the Excel Object
> Library.
>
> See the article "Control Excel from Word" at:
>
> http://www.word.mvps.org/FAQs/InterD...XLFromWord.htm
>
> and the article "Early vs. Late Binding" at:
>
> http://www.word.mvps.org/FAQs/InterD...ateBinding.htm
>
>
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
>
> "Jacob Skaria" <(E-Mail Removed)> wrote in message
> news:2C194C86-6EA0-4B75-894C-(E-Mail Removed)...
> > Dear Abel
> >
> > Try below code after referencing Microsoft Excel Object Library
> >
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > Dim xlApp As Excel.Application
> > Dim xlWB1 As Excel.Workbook
> >
> > Set xlWB1 = xlApp.OpenWorkbook("c:\temp.xls")
> > 'Read values
> > strTemp = xlWB1.Sheets(1).Range("A1")
> > xlWB1.Close
> > Set xlWB1 = Nothing
> >
> > xlApp.Quit
> > Set xlApp = Nothing
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Access Data to Excel/Reimport modified data into Access mlloulou Microsoft Access External Data 5 9th Feb 2009 12:09 PM
Excel form to update data from MS Access data table based on criteriain excel sheet Santa-D Microsoft Excel Programming 2 13th May 2008 03:43 AM
Using Data Access Pages wizard closes Access program =?Utf-8?B?Sm9zaGNhdDk5?= Microsoft Access 1 14th May 2006 07:20 PM
Import Data From Access to Excel - Return Modified Data To Access HVG Microsoft Access External Data 0 9th Dec 2005 08:00 PM
Which program would you use, Excel or Access, to create a data so. =?Utf-8?B?d2Ft?= Microsoft Access 1 20th Oct 2004 10:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:16 PM.