LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Paste data with a macro?

Hi,

Can anyone tell me why the following code causes a Dr. Watson error each
time I try and run it please? I am trying to open a file from the temp
folder, copy data from it and paste this data into another workbook (name
unkown as it will be user defined):

Sub Data_Extract ()

Workbooks.Open FileName:="C:\Temp\DataFile.xls"
Sheets ("Sheet 1").Range("C2:D6000 , H2:H6000").Copy
MsgBox "Data Copied"
If Workbooks.Count 2 Then
MsgBox "Close unneccessary files and restart"
Else
For Each Bk In Workbooks
If Bk.Windows(1).Visible = True Then
If Bk.Name < "DataFile.xls" Then
Bk.Activate
MsgBox "Active"
With ThisWorkbook.Sheets ("Data Sheet")
Range ("A2").Select
'Selection.Paste <= This is where the
'ActiveSheet.Paste macro trips up
End With
End If
End If
Next
End If
End Sub

I am very new to Visual basic and have botched this code together from
various other postings.

This macro will run from a user-defined workbook, so all references to it
must be 'not the other file' (if you see what I mean).

I initially had problems referring between workbooks, but can now do so (I
use the MsgBox to follow the code as it executes). The problem I now face is
pasting the copied data from one workbook into the other.

I'd be very grateful for any advice offered.

Thanks.

Ewan
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to copy & paste data Satish Excel Discussion (Misc queries) 3 December 18th 08 04:50 AM
Macro to paste data pjd33 Excel Discussion (Misc queries) 4 January 17th 07 04:52 PM
macro to select data paste/print Anthony Excel Worksheet Functions 1 January 30th 05 04:35 PM
I need a macro to find cut and paste data to new cell Rex Excel Discussion (Misc queries) 0 December 6th 04 12:45 AM
Macro to paste data into next blank row Cynthia[_3_] Excel Programming 1 February 7th 04 10:11 PM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"