need help with simple syntax error

G

Gwill

What's wrong with the following???? I get "run-time error '9': Subscript
out of range" on the last line

Sub copyfinaldata()
Dim finalreportfile As String

'Open the FINALREPORT file

finalreportfile = InputBox("Open the final report", "Enter filename",
ThisWorkbook.Path & "\test.xls")
Workbooks.Open Filename:=finalreportfile


Windows(finalreportfile).Activate
 
P

Patrick Molloy

add this
DIM WB as Workbook

then change this
Workbooks.Open Filename:=finalreportfile

to
SET WB = Workbooks.Open(finalreportfile)

to don't need to activate the workbook normally as the
newly opened book is usually the active one
however

WB.Activate

this methos gives greater control
eg
WB.Close False
to close without saving

HTH
Patrick Molloy
Microsoft Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top