0
Dim xlsPath As String
xlsPath = "C:\"
Workbooks(xlsPath & "Output.xls").Sheets("Output").Range("B2:B6").Copy

I am trying above code for this but getting error.

Community
  • 1
  • 1
RDP
  • 81
  • 2
  • 13

2 Answers2

0

In order to reference the Workbook xlsPath & "Output.xls", it needs to already be opened in Excel. This is explained in the Workbook Object definition here.

... the workbook must already be open in Microsoft Excel.

What you probably want to do is use the ExecuteExcel4Macro function as was previously answered here.

Community
  • 1
  • 1
farvgnugn
  • 231
  • 2
  • 4
  • Resolved -- I tried below code to access data without opening another excel. Application.ScreenUpdating = False Workbooks.Open Filename:="C:\Output.xls" Workbooks("Input.xls").Worksheets("abc").Activate .............. .............. Workbooks("Output.xls").Close SaveChanges:=False – RDP Mar 05 '14 at 16:36
  • Ok, I answered based on your question - how to do this without opening it. You obviously just meant you didn't want to see it when it was opened. Good job figuring that out. – farvgnugn Mar 07 '14 at 16:06
0

Resolved -- I tried below code to access data without opening another excel.

`Application.ScreenUpdating = False Workbooks.Open Filename:="C:\Output.xls" Workbooks("Input.xls").Worksheets("abc").Activate

Workbooks("Output.xls").Close SaveChanges:=False`

RDP
  • 81
  • 2
  • 13