Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Paste sheet to new file with unknown file name - VBA

Hi-

I currently have a macro that copies "Sheet3" from one file and pastes
it into another file. This works fine right now....because I know the
exact file name. The problem I am forseeing is when I have a file open
and the name is different. Here is my current code:

Windows("Macro_Off_Premise.xls").Activate
Sheets("Sheet3").Select
Sheets("Sheet3").Copy Befo=Workbooks("Off Premise
New.xls").Sheets(1)
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Custom Sort"
Sheets("excel").Select
Range("A1:A3").Select

There will always be two files open. The "Macro_Off_Premise"
file....and another file with an unknown name. How do I copy the sheet
from the macro file to the OTHER OPEN WORKBOOK????

TIA!

-Chris

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Paste sheet to new file with unknown file name - VBA

for each bk in application.workbooks
if bk.Windows(1).visible = True then
if lcase(bk.name) < "macro_off_premise.xls" then
workbooks("Macro_Off_Premise.xls").worksheets("She et3") _
.copy after:=bk.sheets(1)
activesheet.Name = "Custom Sort"
exit for
end if
end if
Next

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
Hi-

I currently have a macro that copies "Sheet3" from one file and pastes
it into another file. This works fine right now....because I know the
exact file name. The problem I am forseeing is when I have a file open
and the name is different. Here is my current code:

Windows("Macro_Off_Premise.xls").Activate
Sheets("Sheet3").Select
Sheets("Sheet3").Copy Befo=Workbooks("Off Premise
New.xls").Sheets(1)
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Custom Sort"
Sheets("excel").Select
Range("A1:A3").Select

There will always be two files open. The "Macro_Off_Premise"
file....and another file with an unknown name. How do I copy the sheet
from the macro file to the OTHER OPEN WORKBOOK????

TIA!

-Chris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Paste sheet to new file with unknown file name - VBA

Tom-

Works great! Thanks again for all your help.

-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
copy the same raws of all sheets from about a 100 file to a new sheet of a book and save the file [email protected] Setting up and Configuration of Excel 0 March 14th 07 02:13 AM
Linked file in same folder but unknown path Christy Excel Programming 6 October 4th 05 06:30 PM
copy/paste from one file to another without file name reference slvrblt Excel Discussion (Misc queries) 4 February 6th 05 08:57 PM
How to Activate unknown file name Ashley[_3_] Excel Programming 1 June 4th 04 06:41 PM
Macro to insert values from a file and save another sheet as a .txt file Frank[_16_] Excel Programming 2 August 28th 03 01:07 AM


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