View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Mass add of a sheet to multiple workbooks

How about a macro?

Are they workbooks all in the same folder (if not put them in the same folder).
Keep the workbook with the macro and worksheet to copy in a separate folder.

Option Explicit
Sub testme01()

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim WksToCopy As Worksheet
Dim TempWkbk As Workbook

Application.ScreenUpdating = False

Set WksToCopy = ThisWorkbook.Worksheets("sheet1")

'change the folder here
myPath = "C:\my documents\excel\test"
If myPath = "" Then Exit Sub
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.xls")
On Error GoTo 0
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myNames) To UBound(myNames)
Application.StatusBar _
= "Processing: " & myNames(fCtr) & " at: " & Now

Set TempWkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr))

With TempWkbk
WksToCopy.Copy _
after:=.Sheets(.Sheets.Count)
End With

TempWkbk.Close savechanges:=True
Next fCtr
End If

With Application
.ScreenUpdating = True
.StatusBar = False
End With

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

ddpderek wrote:

Is it possible to add a sheet from one workbook or file to a bunch of
different work books at the same time or do I have have to copey it to them
all independently?


--

Dave Peterson