View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default Open Workbook in current directory

use thisworkbook.path

--
Don Guillett
SalesAid Software

"Elijah" wrote in message
...
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