473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How can I retrieve multiple cell values by excelexecute4macro()

''I wanted to retrieve values from multiple cells,that is return a column of data(like B7:B13) from a closed workbook and assign it as a cells value in another sheet.I have done it like the following but it is giving error at the executeexcel4macro step.Could somebody tell the reason for this error and any alternative solution.

Thanks in advance

Saptarshi


Sub read()
Dim foldername As String, wb As String, r As Long, cvalue As Variant
Dim wblist() As String, wbcount As Integer, i As Integer, col
Dim startingsource, endingsource, j
foldername = "D:\files"
wbcount = 0
wbname = Dir(foldername & "\" & "*.xls")
While wbname <> ""
wbcount = wbcount + 1
ReDim Preserve wblist(1 To wbcount)
wblist(wbcount) = wbname
wbname = Dir
Wend
If wbcount = 0 Then Exit Sub
startingsource = 7
endingsource = 13
r = 2
d = 7
col = 0
For i = 1 To wbcount
For j = startingsource To endingsource
cvalue = Getfromclosedfile(foldername, wblist(i), "summary", "B7:B13")
Range("A1:A7").Formula = cvalue
Next j
startingsource = 7
endingsource = 13
r = r + 1
col = 0

Next i
End Sub

Private Function Getfromclosedfile(ByVal wbpath As String, wbname As String, wsname As String, cellref As String) As Variant
Dim arg As String
getinfofromclosedfile = ""
If Right(wbpath, 1) <> "\" Then wbpath = wbpath & "\"
If Dir(wbpath & "\" & wbname) = "" Then Exit Function
arg = "'" & wbpath & "[" & wbname & "]" & wsname & "'!" & Range(cellref).Address(True, True, xlR1C1)
On Error Resume Next
Getfromclosedfile = ExecuteExcel4Macro(arg)
End Function
Oct 4 '10 #1
0 894

Sign in to post your reply or Sign up for a free account.

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
0
by: sydney.luu | last post by:
Hello, I have a web page where I dynamically create a TABLE with rows and cells. I fill these cells with application data. As I am building the cell, I add it to a PlaceHolder, which is a...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
1
by: ykong1214 | last post by:
In my project, there is a single select tag, <html:select property="userName" size="7"> <html:options collection="UserList" property="value" labelProperty="label" /> </html:select> ...
1
by: jeganwaran | last post by:
retrieve cell values from the grid view using code
0
by: RKT | last post by:
I have a DataGridView bound to an MS Access table. This is a single- user application. When the User is adding or editing a row, the User may click on a Control elsewhere. That Control has context...
1
by: silentbuddha | last post by:
Hi, I am currently having some difficulties with this sunroutine that I created. My 2 dimensional array is empty. - This code is within my UserForm1 - this sub is suppose to first select the...
2
by: secutos | last post by:
Let's say I have an enumeration like so: public enum Letters { A = 0, B = 1, C = 2, D = 4, E = 8
2
by: ezhar | last post by:
int ctr = dataGridView1.CurrentCellAddress.Y; string str = dataGridView1.Value.ToString(); Form1 frm = (Form1)Application.OpenForms; frm.textBox1.Text = str; I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.