Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Automatic replace of VBE code for multiple files


Automatic replace of VBE code for multiple files


I have few excel files with "C:\Documents and Settings\" couple of time in
the VBE code and in the sheet itself.

Is it possible to loop via al the files (they are all saved in the same
folder) and automatically replace


"C:\Documents and Settings\" with "C:\Dan\" both in the code and on the sheets


Many thanks,
Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Automatic replace of VBE code for multiple files

Dan,

Try this. You will need to change the path to where your workbooks are stored.

Sub LoopThroughDirectory()
Dim sh As Worksheet
Application.DisplayAlerts = False
'Change this to your directory
MyPath = "C:\"
ActiveFile = Dir(MyPath & "*.xls")
Do While ActiveFile < ""
Workbooks.Open Filename:=MyPath & ActiveFile
For Each sh In ActiveWorkbook.Worksheets
sh.Cells.Replace What:="C:\Documents and Settings\", Replacement:="C:\Dan\", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:= _
False, ReplaceFormat:=False
Next
ActiveWorkbook.Save
ActiveWorkbook.Close
ActiveFile = Dir()
Loop
Application.DisplayAlerts = True
End Sub

Mike

"Dan" wrote:


Automatic replace of VBE code for multiple files


I have few excel files with "C:\Documents and Settings\" couple of time in
the VBE code and in the sheet itself.

Is it possible to loop via al the files (they are all saved in the same
folder) and automatically replace


"C:\Documents and Settings\" with "C:\Dan\" both in the code and on the sheets


Many thanks,
Dan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Automatic replace of VBE code for multiple files

Dan,

I missed the bit about changing the code. I don't know how to do that so
this will only change the worksheet text.

Mike

"Mike H" wrote:

Dan,

Try this. You will need to change the path to where your workbooks are stored.

Sub LoopThroughDirectory()
Dim sh As Worksheet
Application.DisplayAlerts = False
'Change this to your directory
MyPath = "C:\"
ActiveFile = Dir(MyPath & "*.xls")
Do While ActiveFile < ""
Workbooks.Open Filename:=MyPath & ActiveFile
For Each sh In ActiveWorkbook.Worksheets
sh.Cells.Replace What:="C:\Documents and Settings\", Replacement:="C:\Dan\", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:= _
False, ReplaceFormat:=False
Next
ActiveWorkbook.Save
ActiveWorkbook.Close
ActiveFile = Dir()
Loop
Application.DisplayAlerts = True
End Sub

Mike

"Dan" wrote:


Automatic replace of VBE code for multiple files


I have few excel files with "C:\Documents and Settings\" couple of time in
the VBE code and in the sheet itself.

Is it possible to loop via al the files (they are all saved in the same
folder) and automatically replace


"C:\Documents and Settings\" with "C:\Dan\" both in the code and on the sheets


Many thanks,
Dan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Automatic replace of VBE code for multiple files

Dan,

Since you double posted the question, I'll work with you in the other post.

Regards,
Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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
Tidy up multiple find and replace code PSM[_10_] Excel Worksheet Functions 2 April 6th 09 02:00 PM
Automatic update multiple files spiz via OfficeKB.com Links and Linking in Excel 2 July 2nd 08 01:54 PM
Modify macro code to export multiple cell contents to multiple Text Files [email protected] Excel Programming 3 October 14th 06 08:26 AM
VBA in Microsoft Excel: Find & Replace method macro across multiple files Pedro123 Excel Programming 0 September 7th 05 03:48 PM
Serach and Replace across multiple files verizon Excel Programming 1 September 30th 03 03:13 PM


All times are GMT +1. The time now is 03:58 PM.

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"