macro/code to insert specific sheet into all workbooks in folder

prkhan56

New Member
Joined
Feb 5, 2003
Messages
23
Hello All,
I am using Excel 2013 and I have a Workbook where I have a Sheet name "Notes"
I want to copy this sheet as the last sheet in all the workbooks in a folder in the following path.
"C:\Username\Macro\Test\"

I got the code on this group from the year 2008 but it does not copy the Notes sheet in any of the workbook in the given path.

This is the link to the thread.

I changed xls to xlsx, the sheet name from "add" to "Notes" and the path accordingly but it still does not copy the "Notes" in all the workbook.

Any help in modifying the existing code or a new code would be greatly appreciated.

Note: Both the codes in the above thread does not work

TIA
 
Maybe... (Subroutine "test_Modified_w_subfolders" will create copy of sheet Notes in all files .xls in folder Test, include subfolders)
VBA Code:
Dim fso As Object, f As Object, f1 As Object, SrcBook As Workbook, fst As Object

Sub test_Modified_w_subfolders()
Dim s As String

s = "C:\Username\Macro\Test\"
s = s & IIf(Right(s, 1) = Application.PathSeparator, "", Application.PathSeparator)

Application.ScreenUpdating = False

Set fst = ThisWorkbook.Worksheets("Notes")
Set fso = CreateObject("Scripting.FileSystemObject")

GetSF s

Application.ScreenUpdating = True

Set SrcBook = Nothing
Set fso = Nothing
Set fst = Nothing
Set f = Nothing

MsgBox "Done!"
End Sub

Private Sub GetSF(path)
Dim SrcBook As Workbook
Set f = fso.GetFolder(path)

    For Each f1 In f.Files
        If Replace(f1.Name, fso.GetBaseName(f1), "") Like ".xls" Then
            Set SrcBook = Workbooks.Open(path & f1.Name)
            fst.Copy After:=SrcBook.Worksheets(SrcBook.Worksheets.Count)
            SrcBook.Close True
        End If
    Next
 
    For Each f In f.SubFolders
        GetSF f.path & Application.PathSeparator
    Next
End Sub
Hello LazyBug,
Your code works but it pops up with and an Exclamation Mark Error saying "Be careful! Parts of your document may include personal information that can't be removed by the Document Inspector." How can we get rid of this please.
Otherwise your code works perfectly.
@Alex thanks for your input. I did change xls to xlsx
Thanks to both of you for all your time and help
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello LazyBug,
Your code works but it pops up with and an Exclamation Mark Error saying "Be careful! Parts of your document may include personal information that can't be removed by the Document Inspector." How can we get rid of this please.
Otherwise your code works perfectly.
@Alex thanks for your input. I did change xls to xlsx
Thanks to both of you for all your time and help
Glad we could help & thanks for the feedback.

Go to File > Options > Trust Center > Trust Center Settings > Privacy Options > uncheck the check box "Remove personal information from file properties on save", then OK.
 
Upvote 0
Glad we could help & thanks for the feedback.

Go to File > Options > Trust Center > Trust Center Settings > Privacy Options > uncheck the check box "Remove personal information from file properties on save", then OK.
Dear LazyBug,
Thanks for your prompt response.
It is unchecked but it still pops up and only when I press Ok then it processes the next file so on and so forth till it displays the MsgBox Done.
Any guess?
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top