LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default VBA Script to use any open file when copying and pasting

Dim myFileName As String
Dim myWorksheet As String
'assume you want to return to current workbook after
' creating new workbook
myFileName = Application.ActiveWorkbook.Name
'assume you want to return to current worksheet after
' creating new workbook
myWorksheet = Application.ActiveSheet.Name

Workbooks.Add

Windows(myFileName).Activate
Sheets(myWorksheet).Select

--
HTH,
Gary Brown

If this post was helpful to you, please select ''YES'' at the bottom of the
post.



"Charles" wrote:

I have a VBA script that copys data from a particular excel sheet into a new
workbook.

Currently, if the file name changes, the script does not work. For the code
below, what do I need to enter that ANY file name will work.

Workbooks.Add
Windows("SpecificFile.xls").Activate
Sheets("Assumptions").Select

What would replace Windows("SpecificFile.xls").Activate such that if a file
opened called File1.xls, or File9.xls, etc, woudl work.

Charles

 
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
copying and pasting to a different xls file in a different directo dr chuck Excel Programming 4 November 2nd 06 03:04 PM
copying and pasting to a different xls file in a different directo dr chuck Excel Programming 0 July 27th 06 04:16 AM
copying from one file pasting in another tim64[_54_] Excel Programming 4 July 8th 05 11:28 PM
Pasting formulas without copying file ref. John Tolman[_2_] Excel Programming 1 July 15th 04 02:31 AM
How do I add a File Open box to this script??? maleemi Excel Programming 3 March 6th 04 08:56 PM


All times are GMT +1. The time now is 06:43 AM.

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"