LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Loop through, open, and modify all workbooks in file

I have some code which I found on this board previously. The code
essentially opens all Workbooks in a file directory ("Test" below), goes to
sheet 1 and puts the value 1000 in range A1. The code is essentially doing
what it is supposed to, however, I need to make it more complex. I will be
working from a workbook that serves as the master workbook ("Master.xls")
which also contains the coding. While having the "Master" workbook open, I
want it to open each workbook individually (the "Secondary" workbooks) in the
directory and perform the following steps:

(1) Delete "Sheet3" from the Secondary workbook (2) Create a copy of
"Sheet3" from the Master workbook and insert into the Secondary workbook (3)
Update links (there are formulas in sheet3) so they reference the secondary
workbook that is open (name of workbook varies depending on which one is
open) (4) Save the secondary workbook, close , and go onto the next file.

Here is what I have so far, any help on modifying this would be appreciated.
Thanks.


Sub UpdateTheData()
Dim basebook As Workbook
Dim mybook As Workbook
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = "C:\Documents and Settings\Jason\Desktop\Test"
MyPath = "C:\Documents and Settings\Jason\Desktop\Test"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If
Application.ScreenUpdating = True
Set basebook = ThisWorkbook
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)

' I BELIEVE CODE WOULD GO HERE TO PERFORM STEPS ABOVE

Sheets("Sheet1").Select
Range("A1").Value = 1000
mybook.Close True
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub

 
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
Loop Through All Open Workbooks scott Excel Programming 11 February 1st 05 02:58 AM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM
Loop through all Open workbooks Stuart[_5_] Excel Programming 3 June 7th 04 08:07 PM
Loop through open workbooks Bob Phillips[_6_] Excel Programming 2 April 28th 04 09:28 AM
Can I have a loop to open a set of workbooks get some data, close it one a time. wellie Excel Programming 2 July 9th 03 04:58 AM


All times are GMT +1. The time now is 12:40 PM.

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

About Us

"It's about Microsoft Excel"