0

I am accessing one application.Through application one excel file is getting open(not saving it in downloads,directly opening).Now I need to read data from the unsaved excel.Is it possible that without saving the file,can we read the data??I have tried the below code:

Set objExcel = GetObject(,"Excel.Application")
Set objWorkbook = objExcel.WorkBooks("143317473_1.xls")
Set NewSheet = objWorkBook.Sheets.Item(1) 
GetValuesFromUnsavedExcelFile = NewSheet.Cells(2, 1)

I am getting error: "Subscript out of Range at line 50".

So,is it necessary to save file before reading it??

2
  • Did the solution help? Commented May 26, 2017 at 6:08
  • yes..@Kira.. thanks.. Commented May 31, 2017 at 2:24

1 Answer 1

3

I ran your code and it worked fine for me only If I provide the correct name of the workbook. I got the error mentioned by you only when I provided incorrect workbook name, so you need to be sure about the workbook Name.

Also, If there is only one workbook opened at the time this code is running, you can very well use the currently active workbook as below:

Set objWorkbook = objExcel.ActiveWorkBook

Also, to answer the 2nd part of your question, No, It is not necessary to save the excel before you can read it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.