Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read the value of a cell from another excel file without opening it
#1
You have an excel file at location D:\ (example D:\fromdata.xlsx ) and you want to read its cell value E2 and put it inside the file located at C:\ (example C:\todata.xlsx )

Open your file at C:\todata.xlsx go to Developer Tab and then insert a button

copy below codes and paste between the Command Button click  (just below Button1_Click())

Dim wkbk1 As Workbook
Set wkbk1 = Workbooks.Open("D:\fromdata.xlsx")
Dim cellvalueofdatafile As Variant
cellvalueofdatafile = wkbk1.Sheets("Sheet1").Range("E" & 2)
wkbk1.Close

ThisWorkbook.Sheets("Sheet1").Range("A" & 1) = cellvalueofdatafile

[Image: excel%20automation%201.JPG]

now we have the cell value of E2 (of D:\fromdata.xlsx, Sheet1) in the variable cellvalueofdatafile which can be put it inside your file

A1 by using the formula ThisWorkbook.Sheets("Sheet1").Range("A" & 1) = cellvalueofdatafile

Save it as macro enabled file
Reply
#1
You have an excel file at location D:\ (example D:\fromdata.xlsx ) and you want to read its cell value E2 and put it inside the file located at C:\ (example C:\todata.xlsx )

Open your file at C:\todata.xlsx go to Developer Tab and then insert a button

copy below codes and paste between the Command Button click  (just below Button1_Click())

Dim wkbk1 As Workbook
Set wkbk1 = Workbooks.Open("D:\fromdata.xlsx")
Dim cellvalueofdatafile As Variant
cellvalueofdatafile = wkbk1.Sheets("Sheet1").Range("E" & 2)
wkbk1.Close

ThisWorkbook.Sheets("Sheet1").Range("A" & 1) = cellvalueofdatafile

[Image: excel%20automation%201.JPG]

now we have the cell value of E2 (of D:\fromdata.xlsx, Sheet1) in the variable cellvalueofdatafile which can be put it inside your file

A1 by using the formula ThisWorkbook.Sheets("Sheet1").Range("A" & 1) = cellvalueofdatafile

Save it as macro enabled file
Reply
CAA


Messages In This Thread
Read the value of a cell from another excel file without opening it - by techberth - 23-11-2019, 12:30 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)