Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default 2 Files open - Paste to One

Hi-

I have a macro saved in a file ("Macro1.xls"). This macro opens a
file.....does it's thing...closes the file....opens the next
file....does it's thing....closes that file.....etc. This goes on for
over 100 files.

I just added a copy and paste feature that grabs cell values from the
"Macro1.xls" file and pastes them into the open file. The problem I
have is the name of these files changes from day to day. Currently I
have this code which works for a file with the specific file name
"Chris.xls":

Windows("Macro1.xls").Activate
Sheets("Sheet5").Select
Rows("1:2").Select
Selection.Copy
Windows("Chris.xls").Activate
Selection.Insert Shift:=xlDown

Can anyone recommend some code that will paste this value in the file
that is open that is not named "Macro1.xls"?? The only two Excel files
that will be open when this macro runs are the macro file and the final
data file.

TIA!

-Chris

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 2 Files open - Paste to One

Dim bk as Workbook
set bk = Workbooks.Open(sName)
Workbooks("Macro1.xls").Worksheets("Sheet5").Range ("1:2").copy
bk.Worksheets(1).Rows(3).Insert Shift:=xldown

Adjust to insert at the appropriate location.

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
Hi-

I have a macro saved in a file ("Macro1.xls"). This macro opens a
file.....does it's thing...closes the file....opens the next
file....does it's thing....closes that file.....etc. This goes on for
over 100 files.

I just added a copy and paste feature that grabs cell values from the
"Macro1.xls" file and pastes them into the open file. The problem I
have is the name of these files changes from day to day. Currently I
have this code which works for a file with the specific file name
"Chris.xls":

Windows("Macro1.xls").Activate
Sheets("Sheet5").Select
Rows("1:2").Select
Selection.Copy
Windows("Chris.xls").Activate
Selection.Insert Shift:=xlDown

Can anyone recommend some code that will paste this value in the file
that is open that is not named "Macro1.xls"?? The only two Excel files
that will be open when this macro runs are the macro file and the final
data file.

TIA!

-Chris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default 2 Files open - Paste to One

Hi Tom-

Thanks for the reply. This code errors on the set bk line. It is
giving me a run-time error 1004.

Just to be clear....the file that is being pasted into is already open
at the point this code is run. Not sure what the (sName) code is above
as well...

Thanks,
Chris

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 2 Files open - Paste to One

That is the point Chris. You say you are processing 100 files, so it
doesn't open itself. When you open it, set a reference to it and use that
reference.

for example, if you were opening all the files in a single directory

Dim bk as Workbook
Dim sName as String
sName = Dir("C:\Myfolder\*.xls")
do while sName < ""
set bk = Workbooks.Open("C:\MyFolder\" & sName)
Workbooks("Macro1.xls").Worksheets("Sheet5").Range ("1:2").copy
bk.Worksheets(1).Rows(3).Insert Shift:=xldown
loop

Adapt if you are working through a list of names.

--
Regards,
Tom Ogilvy



wrote in message
ps.com...
Hi Tom-

Thanks for the reply. This code errors on the set bk line. It is
giving me a run-time error 1004.

Just to be clear....the file that is being pasted into is already open
at the point this code is run. Not sure what the (sName) code is above
as well...

Thanks,
Chris



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default 2 Files open - Paste to One

Tom-

Thanks for the help. Everything is running properly. I appreciate the
explanation and the help.

Take Care,
Chris



Reply
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
how do I toggle between 2 open excel files and leave both open Big D in Brighton Excel Discussion (Misc queries) 1 November 6th 08 04:28 PM
How to change default Open/Files of Type to "Microsoft Excel Files Tammy Excel Discussion (Misc queries) 2 January 14th 08 11:06 PM
Macro to open *.dat files and save as .txt (comma delimited text files) [email protected] Excel Programming 2 November 30th 05 05:50 AM
Open multiple text files and paste contents to single cell [email protected] Excel Programming 1 October 19th 05 04:05 PM
file open via IE hyperlink causes already open files to shrink and tile Marc Setting up and Configuration of Excel 0 May 4th 05 08:13 PM


All times are GMT +1. The time now is 11:51 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"