Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to insert specified tabs to all workbooks in folder

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Macro to insert specified tabs to all workbooks in folder

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to insert specified tabs to all workbooks in folder

Rowan...your "night owl" tendencies are much appreciated!! I'll try it out
and update you later tonight (this morning)

"Rowan" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Macro to insert specified tabs to all workbooks in folder

Or this afternoon if you happen to be in Sydney as I am...

"need_some_help" wrote:

Rowan...your "night owl" tendencies are much appreciated!! I'll try it out
and update you later tonight (this morning)

"Rowan" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to insert specified tabs to all workbooks in folder

Rowan, I engrafted this code (with a few minor customizations) into my
program as a call to Openfiles and it compiles and runs fine but does not
create the new tabs in each of the workbooks in the directory. Is there a
special way to invoke the procedure? Should I pass the directory as an
object or something? Thanks for your help

"Rowan" wrote:

Or this afternoon if you happen to be in Sydney as I am...

"need_some_help" wrote:

Rowan...your "night owl" tendencies are much appreciated!! I'll try it out
and update you later tonight (this morning)

"Rowan" wrote:

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

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
Is there any way to create a folder structure for tabs in a workbo Curious Excel Discussion (Misc queries) 4 April 2nd 23 08:10 PM
Folder/Tabs Newbie Question Andrew Excel Discussion (Misc queries) 2 March 15th 10 06:08 PM
i created a macro in a xlstart folder.how do i do to insert in too Roughar Excel Discussion (Misc queries) 1 October 21st 09 01:48 PM
Shared folder - tabs disappear while saving gizmo Excel Worksheet Functions 0 February 3rd 05 10:36 AM
Macro to Open all workbooks in a folder and change default font Carlton A. Barlow Excel Programming 1 October 15th 04 01:38 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"