简体   繁体   中英

how to open worksheet by passing value into variable in VBA

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")

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM