Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Getting values from anotjer workbook

Hi,

I'm making statistic analyzes for school project and I have problem.

I have been trying to get values from another workbook to the one I'm making
statistical totals.

I would like to get the info straight from the workbook, without copying it
first to the main workbook.

I have made CommandButtons to the main sheet and have been trying to use
Worksheet and Workbook statements without success.

Does anyone have good tips to solve this?

Br, Miipe


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Getting values from anotjer workbook

Open both workbooks. From one workbook, in a cell type "=" then click on a
cell in the other workbook. Hit enter.

If you inspect the cell from in the first workbook, it will show you how to
reference the other workbook.

Scott

"Miikka Hamalainen" wrote:

Hi,

I'm making statistic analyzes for school project and I have problem.

I have been trying to get values from another workbook to the one I'm making
statistical totals.

I would like to get the info straight from the workbook, without copying it
first to the main workbook.

I have made CommandButtons to the main sheet and have been trying to use
Worksheet and Workbook statements without success.

Does anyone have good tips to solve this?

Br, Miipe



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Getting values from anotjer workbook

Hi,

I did this, but when I try to add this to CommandButton VBA script I get
error message

The script I'm using is following:

Worksheet("Total").Cells( 2, 12).Value = "here should be the other workbook
and its cells and values of the selected cells"

I have tried Workbook.Open-statement, but didn't work.

Br, Miipe

"Scott buckwalter" kirjoitti
...
Open both workbooks. From one workbook, in a cell type "=" then click on

a
cell in the other workbook. Hit enter.

If you inspect the cell from in the first workbook, it will show you how

to
reference the other workbook.

Scott

"Miikka Hamalainen" wrote:

Hi,

I'm making statistic analyzes for school project and I have problem.

I have been trying to get values from another workbook to the one I'm

making
statistical totals.

I would like to get the info straight from the workbook, without copying

it
first to the main workbook.

I have made CommandButtons to the main sheet and have been trying to use
Worksheet and Workbook statements without success.

Does anyone have good tips to solve this?

Br, Miipe





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting values from anotjer workbook

John Walkenbach has some code that will allow a macro (not a worksheet
function) retrieve values from a closed workbook.

http://j-walk.com/ss/excel/eee/eee009.txt
Look for either: GetDataFromClosedFile or GetValue.



Miikka Hamalainen wrote:

Hi,

I'm making statistic analyzes for school project and I have problem.

I have been trying to get values from another workbook to the one I'm making
statistical totals.

I would like to get the info straight from the workbook, without copying it
first to the main workbook.

I have made CommandButtons to the main sheet and have been trying to use
Worksheet and Workbook statements without success.

Does anyone have good tips to solve this?

Br, Miipe


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Getting values from anotjer workbook

Thanks, It works and it's much easier. I added this function to command
button and now I can run it just by clicking.

Now that it works, I have another question:
If I have many workbooks I need to get certain values to the same
worksheet, how should I do it?

Can I use this script or do I have to make totally new?

Br, Miipe



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting values from anotjer workbook

You could loop and get the values or you could just use a bunch of formulas in
another worksheet that point at the folders/workbooks/worksheets/ranges that you
want.

Those formulas would look like:
='C:\my documents\excel\[book2.xls]Sheet1'!$A$1

===

or looping in code...

Option Explicit
Option Base 1
Sub testme()

Dim myLocations As Variant
Dim iCtr As Long

myLocations = Array( _
Array("c:\my documents\excel", "book3.xls", "sheet1", "A1"), _
Array("c:\my documents\excel", "book4.xls", "sheet1", "A1"), _
Array("c:\my documents\excel", "book5.xls", "sheet1", "A1"), _
Array("c:\my documents\excel", "book6.xls", "sheet1", "A1"))

For iCtr = LBound(myLocations) To UBound(myLocations)
MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2), _
myLocations(iCtr)(3), myLocations(iCtr)(4))
Next iCtr

End Sub

'From John Walkenbach
Private Function GetValue(path, file, sheet, range_ref)

' Retrieves a value from a closed workbook

Dim arg As String

' Make sure the file exists

If Right(path, 1) < "\" Then path = path & "\"

If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If

' Create the argument

arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)

' Execute an XLM macro

GetValue = ExecuteExcel4Macro(arg)

End Function



wrote:

Thanks, It works and it's much easier. I added this function to command
button and now I can run it just by clicking.

Now that it works, I have another question:
If I have many workbooks I need to get certain values to the same
worksheet, how should I do it?

Can I use this script or do I have to make totally new?

Br, Miipe


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Getting values from anotjer workbook

I get compile error "argument not optional" on GetValue

For iCtr = LBound(myLocations) To UBound(myLocations)
MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2),
myLocations(iCtr)(3))

Next iCtr

Something wrong?

Br, Miipe

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting values from anotjer workbook

You dropped the 4th parm.

MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2), _
myLocations(iCtr)(3), myLocations(iCtr)(4))



wrote:

I get compile error "argument not optional" on GetValue

For iCtr = LBound(myLocations) To UBound(myLocations)
MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2),
myLocations(iCtr)(3))

Next iCtr

Something wrong?

Br, Miipe


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting values from anotjer workbook

No.

You'll need 4 parms for each value to return.

You need to specify the path, workbook name, sheet name, and cell address.

But you'll have entries in this portion:

myLocations = Array( _
Array("c:\my documents\excel", "book3.xls", "sheet1", "A1"), _
Array("c:\my documents\excel", "book4.xls", "sheet1", "A1"), _
Array("c:\my documents\excel", "book5.xls", "sheet1", "A1"))



Miikka Hamalainen wrote:

Yes, but what if I have only 3 files I need to get the info, then I should
have 3 parameters, right?

Br, Miipe

"Dave Peterson" kirjoitti
...
You dropped the 4th parm.

MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2), _
myLocations(iCtr)(3), myLocations(iCtr)(4))



wrote:

I get compile error "argument not optional" on GetValue

For iCtr = LBound(myLocations) To UBound(myLocations)
MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2),
myLocations(iCtr)(3))

Next iCtr

Something wrong?

Br, Miipe


--

Dave Peterson


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting values from anotjer workbook

But you'll have FEWER entries in this portion:

(oops)

Dave Peterson wrote:

No.

You'll need 4 parms for each value to return.

You need to specify the path, workbook name, sheet name, and cell address.

But you'll have entries in this portion:

myLocations = Array( _
Array("c:\my documents\excel", "book3.xls", "sheet1", "A1"), _
Array("c:\my documents\excel", "book4.xls", "sheet1", "A1"), _
Array("c:\my documents\excel", "book5.xls", "sheet1", "A1"))

Miikka Hamalainen wrote:

Yes, but what if I have only 3 files I need to get the info, then I should
have 3 parameters, right?

Br, Miipe

"Dave Peterson" kirjoitti
...
You dropped the 4th parm.

MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2), _
myLocations(iCtr)(3), myLocations(iCtr)(4))



wrote:

I get compile error "argument not optional" on GetValue

For iCtr = LBound(myLocations) To UBound(myLocations)
MsgBox GetValue(myLocations(iCtr)(1), myLocations(iCtr)(2),
myLocations(iCtr)(3))

Next iCtr

Something wrong?

Br, Miipe

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
comparing values from one workbook with another workbook dpdave Excel Discussion (Misc queries) 3 February 10th 10 04:55 PM
How do I call number values form one workbook to another workbook Teryn Excel Worksheet Functions 3 December 29th 07 09:21 AM
How do I post values from source workbook to destination workbook Raghavendra Kulkarni Excel Programming 1 May 4th 05 01:31 PM
Values from another workbook Ajit Excel Programming 3 December 13th 04 08:40 PM
Setting values in another workbook Ecco Excel Programming 1 July 17th 03 08:15 AM


All times are GMT +1. The time now is 12:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"