Open Workbook in current directory

E

Elijah

Hi, I'm using 2 workbooks in my forecast model. Can some help with a macro
to transfer data between the workbooks?

I have so far recorded a copy-paste special macro to transfer data, but what
I want to do is:
- If the workbook is open then activate the relevant sheet and copy and
paste data between workbooks, otherwise open the relevant workbook.
- Be able to store the 2 workbooks in any directory and still have the macro
work.

I've tried the following macro - but I get an error with the use of the Me.
construct:

Sub CopyData()

Dim sFileName As String
sFileName = "SpreadsheetB.xls"

On Error Resume Next
Workbooks("SpreadsheetB.xls").Activate
If Err.Number > 0 Then
Workbooks.Open Me.Path & "\" & sFileName
End If
On Error GoTo 0

Sheets("Forecast").Select
Rows("2:270").Select
Selection.Copy
......

Does anyone tell me what I've done wrong here?

Thanks

Elijah
 
B

Bob Phillips

Me refers to a container, such as a form or a worksheet class. You probably
want ActiveWorkbook here, or ThisWorkbook if it will be the workbook that
the macro is stored in.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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