I would like to have a batch file that would copy a sheet from a spreadsheet to each of 185 spreadsheets.
The sheet to be copied would be [count.xlsx]Count!
The spreadsheets are ARM1.xlsx through ARM185.xlsx.
suggestions?
thanks!
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Batch file to copy sheet
J.E.
This VBA placed in the count.xlsx workbook and renamed to count.xlsm should do the trick.
Option Explicit Sub MassCopySheet() Dim wkbkSource As Workbook Dim wsSource As Worksheet Dim wkbkDest As Workbook Dim iWkBKCntr As Integer Application.ScreenUpdating = False Set wkbkSource = ActiveWorkbook Set wsSource = wkbkSource.Sheets("Count") 'Source Sheet to copy For iWkBKCntr = 1 To 185 On Error Resume Next Set wkbkDest = Workbooks.Open("ARM" & Format(iWkBKCntr) & ".xlsx") On Error GoTo 0 If Not wkbkDest Is Nothing Then wsSource.Copy After:=wkbkDest.Sheets(1) Application.DisplayAlerts = False With wkbkDest .Save .Close End With End If 'wkbkDest Nothing Next iWkBKCntr End Sub
Notes:
1. The code compiles correctly.
2. The code runs correctly to end. Of course I don’t have any of the ARM workbooks so all I’ve really tested is the error trap for missing files in the series, which works.
3. You need to add a drivepath to the destination workbook name if it is not in the same directory as the count.xlsx file.
4. If you don’t want the copied sheet to follow Sheet 1 then you need to change the AFTER clause of the Copy command with the appropriate number or with the Sheet Name in quotes.
:cheers:
Wassim,
Somehow, I don’t think linking 185 workbooks is a very good idea. :cheers:
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications