Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Adapted from a post by Bob Phillips. Adds two sheets called AddOne and AddTwo
if they do not allready exist in the files: Sub OpenFiles() Dim objFSO As Object Dim objFolder As Object Dim objSubfolder As Object Dim objFile As Object Dim sht1 As Worksheet Dim sht2 As Worksheet Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder("c:\Temp") For Each objFile In objFolder.Files If objFile.Type = "Microsoft Excel Worksheet" Then Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name On Error Resume Next Set sht1 = Sheets("AddOne") Set sht2 = Sheets("AddTwo") On Error GoTo 0 If sht1 Is Nothing Then Set sht1 = Sheets.Add sht1.Name = "AddOne" End If If sht2 Is Nothing Then Set sht2 = Sheets.Add sht2.Name = "AddTwo" End If ActiveWorkbook.Close True Set sht1 = Nothing Set sht2 = Nothing End If Next End Sub Hope this helps Rowan "need_some_help" wrote: I'm working on a loop that will open all workbooks in a folder and add two specified tabs to each workbook. Important factors include my ability to choose the name of the two tabs and for the loop to carry on through the entire folder servicing all workbooks. Any suggestions |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Is there any way to create a folder structure for tabs in a workbo | Excel Discussion (Misc queries) | |||
Folder/Tabs Newbie Question | Excel Discussion (Misc queries) | |||
i created a macro in a xlstart folder.how do i do to insert in too | Excel Discussion (Misc queries) | |||
Shared folder - tabs disappear while saving | Excel Worksheet Functions | |||
Macro to Open all workbooks in a folder and change default font | Excel Programming |