0

I'm trying to open worksheet by taking value from one cell and concate the desire file name but it shows error : object variable or with block variable not set i'm using following code : where "123.xlsx" is name of workbook that i want to open .

Dim output_path As Workbook
dim xlwkbrpt1  as workbook
output_path = Application.ActiveWorkbook.ActiveSheet.Range("F14").Value
Set xlwkbrpt1 = xlApp.Workbooks.Open(output_path & "\" & "123.xlsx")
4
  • 1
    Why is output_path a Workbook? Shouldn't it be a string? Also, print output_path & "\" & "123.xlsx" just before executing the last statement and see what the Open method is trying to open. Commented Nov 19, 2016 at 6:50
  • @FDavidov it shows same error even i change the datatype Commented Nov 19, 2016 at 7:33
  • Please add a print of the parameter to xlApp.Workbooks.Openjust before the invocation and append the result to your question. Commented Nov 19, 2016 at 10:42
  • By the way, I see that your comment to the answer by bzimor states that the solution does nor work, but the answer is flagged as resolving the issue. So is the issue solved or not? Commented Nov 19, 2016 at 10:43

1 Answer 1

1

You declared variable output_path with wrong type. Try this:

Dim output_path As String
Dim xlwkbrpt1  As Workbook
output_path = Application.ActiveWorkbook.ActiveSheet.Range("F14").Value
Set xlwkbrpt1 = Workbooks.Open(output_path & "\" & "123.xls")
Sign up to request clarification or add additional context in comments.

1 Comment

I apllied your code with correction of dattype but it's still showing same error

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.