Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Do Until macro that renames workbooks and keeps the original workbook open

I need help writing code for the following process:

I have a 'master' workbook consisting of 3 sheets; data, table and pie
chart. In addition I have multiple Excel workbooks, each with 'data'
for a different geography. These 'data' files have the identical
range; A1:Q18. The scenario is 50+ 'data' workbooks open, along with
the 'master' workbook containing the 'report' and 'pie chart'. The
'report' tab is linked to the 'data' sheet, while the 'pie chart' is
linked to the report. I'm trying to write a 'Do Until' macro that
begins with the first 'data' file, copies an exact range from it,
pastes the range onto the 'data' sheet in the 'master' workbook at cell
A1, renames the workbook based on a name in a specific cell of the new
'data'. Then 'saves and closes' the new workbook, and then repeats the
process with the next 'data' workbook.

My problem is once I rename the original 'master' workbook it's closed,
so my Do Until statement stops.

Does anyone have any ideas on how I can write code to make this work.

Thank you,

Tony

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Do Until macro that renames workbooks and keeps the original workbook open

This should get you started. Change the ranges to suit

Sub ProcessFiles()
Dim FSO As Object
Dim i As Long
Dim sFolder As String
Dim fldr As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object
Dim nTotals As Double
Dim sNewName As String

Set FSO = CreateObject("Scripting.FileSystemObject")

sFolder = "C:\Data"
If sFolder < "" Then
Set Folder = FSO.GetFolder(sFolder)

Set Files = Folder.Files
For Each file In Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
With ActiveWorkbook
sNewName = .Worksheets("Sheet1").Range("M1").Value
.Worksheets("Sheet1").Range("A1:Q18").Copy _
ThisWorkbook.Worksheets("Sheet1").Range("A1")
.Close savechanges:=False
End With
ThisWorkbook.SaveAs Filename:=sNewName
End If
Next file

End If ' sFolder < ""

End Sub


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

wrote in message
oups.com...
I need help writing code for the following process:

I have a 'master' workbook consisting of 3 sheets; data, table and pie
chart. In addition I have multiple Excel workbooks, each with 'data'
for a different geography. These 'data' files have the identical
range; A1:Q18. The scenario is 50+ 'data' workbooks open, along with
the 'master' workbook containing the 'report' and 'pie chart'. The
'report' tab is linked to the 'data' sheet, while the 'pie chart' is
linked to the report. I'm trying to write a 'Do Until' macro that
begins with the first 'data' file, copies an exact range from it,
pastes the range onto the 'data' sheet in the 'master' workbook at cell
A1, renames the workbook based on a name in a specific cell of the new
'data'. Then 'saves and closes' the new workbook, and then repeats the
process with the next 'data' workbook.

My problem is once I rename the original 'master' workbook it's closed,
so my Do Until statement stops.

Does anyone have any ideas on how I can write code to make this work.

Thank you,

Tony



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Do Until macro that renames workbooks and keeps the original workbook open

Bob,

Thank you very much...I think this did it...

Thank you

I owe you....

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
Search and open excel workbooks from a master workbook ECM Excel Discussion (Misc queries) 1 April 25th 08 04:58 PM
Macro To consolidate All Open Workbooks Into One Workbook carl Excel Worksheet Functions 3 March 31st 07 04:22 AM
Copy worksheet from Active workbook into all other open workbooks TroyB[_2_] Excel Programming 0 February 10th 04 10:29 AM
very difficult code that will close original workbook and leave another open reesmacleod Excel Programming 4 December 3rd 03 11:21 PM
copy sheet1 from all open workbooks to one workbook Mike[_61_] Excel Programming 2 October 31st 03 02:16 PM


All times are GMT +1. The time now is 05:07 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"