PC Review


Reply
Thread Tools Rate Thread

copy past two existing sheets into 30 workbooks

 
 
raffrobb
Guest
Posts: n/a
 
      21st Jul 2009
I want to copy paste two existing sheets into 30 workbooks in a
folder.
The sheets are in a workbook called Master, and I need to make a copy/
move and insert into each workbook within the folder.

What is the simplest way to do this via VBA?

Thanks,
Robb
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Jul 2009
You will need something like this:

Sub dk()
For Each wb In myFolder.Workbooks
For i = 1 To 2
Workbooks("Master").Sheets(i).Copy +
After:=wb.Sheets(wb.Sheets.Count)
Next
Next
End Sub

This is totally untested and is only to give guidance as to structure for
creating a workable loop to go through the folder of files and copy
worksheets to them. Some things that have to happen are, each workbook in
the folder will have to be opened and then closed after the copy event. The
myFolder variable will need to include path.




"raffrobb" <(E-Mail Removed)> wrote in message
news:35f1a6cc-ee94-4510-9666-(E-Mail Removed)...
>I want to copy paste two existing sheets into 30 workbooks in a
> folder.
> The sheets are in a workbook called Master, and I need to make a copy/
> move and insert into each workbook within the folder.
>
> What is the simplest way to do this via VBA?
>
> Thanks,
> Robb



 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Jul 2009
I need to proof read these before entering. Change the + To _

You will need something like this:

Sub dk()
For Each wb In myFolder.Workbooks
For i = 1 To 2
Workbooks("Master").Sheets(i).Copy _
After:=wb.Sheets(wb.Sheets.Count)
Next
Next
End Sub

This is totally untested and is only to give guidance as to structure for
creating a workable loop to go through the folder of files and copy
worksheets to them. Some things that have to happen are, each workbook in
the folder will have to be opened and then closed after the copy event. The
myFolder variable will need to include path.





"JLGWhiz" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> You will need something like this:
>
> Sub dk()
> For Each wb In myFolder.Workbooks
> For i = 1 To 2
> Workbooks("Master").Sheets(i).Copy +
> After:=wb.Sheets(wb.Sheets.Count)
> Next
> Next
> End Sub
>
> This is totally untested and is only to give guidance as to structure for
> creating a workable loop to go through the folder of files and copy
> worksheets to them. Some things that have to happen are, each workbook in
> the folder will have to be opened and then closed after the copy event.
> The myFolder variable will need to include path.
>
>
>
>
> "raffrobb" <(E-Mail Removed)> wrote in message
> news:35f1a6cc-ee94-4510-9666-(E-Mail Removed)...
>>I want to copy paste two existing sheets into 30 workbooks in a
>> folder.
>> The sheets are in a workbook called Master, and I need to make a copy/
>> move and insert into each workbook within the folder.
>>
>> What is the simplest way to do this via VBA?
>>
>> Thanks,
>> Robb

>
>



 
Reply With Quote
 
marcus
Guest
Posts: n/a
 
      22nd Jul 2009
Hi Rob

This will open all the excel in a designated folder. You will need to
change the file path to suit and also the names of the sheets to
copy. This macro assumes you are running it from the Master
spreadsheet. Hope this helps.

Take care

Marcus


Sub CopytoXLFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbThis As Workbook
Dim dblValue As Double
Dim WbCnt As Long
Dim Wrkbook As String

With Application
On Error Resume Next
Set wbThis = ThisWorkbook
dblValue = 0
WbCnt = 0
With .FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\MS2642\MyXLFiles
\Personal\FoldertoOpen\" '<-Change path to suit
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through
all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open
(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Wrkbook = ActiveWorkbook.Name
wbThis.Activate
Sheets(Array("Test1", "Test2")).Copy
Before:=Workbooks(Wrkbook).Sheets(1)
wbResults.Activate
WbCnt = WbCnt + 1
Next lCount
End If
End With
End With
End Sub
 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      22nd Jul 2009
See also
http://www.rondebruin.nl/copy4.htm

See the last example



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"raffrobb" <(E-Mail Removed)> wrote in message news:35f1a6cc-ee94-4510-9666-(E-Mail Removed)...
>I want to copy paste two existing sheets into 30 workbooks in a
> folder.
> The sheets are in a workbook called Master, and I need to make a copy/
> move and insert into each workbook within the folder.
>
> What is the simplest way to do this via VBA?
>
> Thanks,
> Robb

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot copy & past beween workbooks LL Microsoft Excel Misc 1 11th Mar 2010 05:36 AM
Copy and past to different sheets zgclub Microsoft Excel Misc 4 9th Feb 2006 11:58 AM
inserting sheets into existing workbooks w/o external references =?Utf-8?B?c3BlbmNl?= Microsoft Excel Worksheet Functions 3 19th Dec 2005 04:33 PM
Copy & Past from multiple sheets to one Prometheus Microsoft Excel Programming 18 5th Dec 2005 12:36 AM
Array Sheets Copy to new Workbooks Witek Kruk Microsoft Excel Programming 2 18th Oct 2004 01:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:34 AM.