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: 102
Default VBA to find filename and replace

Hi
I just found the answer to "Find and Replace in VBA" and tried to adapt it
for what I'm doing, but it's more difficult so I need some help please.

I have multiple worksheets in an excel 2007 workbook - a monthly report.
Within the worksheets I have many cells that link to last months workbooks -
(i.e I compare last month figures to this months figures).

I need the macro to do the following:

- Create an Input box for the user to "enter the name ofTHE OLD months
workbook"

- Create an Input box for the user to "enter the name of THE NEW months
workbook"

- Excel finds cells with links containing the OLD workbook name and replaces
it with the NEW workbook name

The problem:

After the user enters the NEW name excel asks the user to also select the
new workbook from a window and sometimes requires the worksheet to be
selected as well.

Is there any way to stop this requirement, but to ensure that the revised
links work?

I tried including "Application.ScreenUpdating = False" and
"Application.DisplayAlerts = False", but then the revised formulas turned to
#REF once all of the old & new workbook names had been entered (9 times each
for 9 worksheets).

Also - is there a way to enter the Old and New workbook names once instead
of once for every worksheet in the workbook?

Old worksheet name:
..../[Plan for Restructuring and Rebudgeting as at 06_10_09 XP
version.xls]/Monthly Detailed P&L

New worksheet name:
..../[Plan for Restructuring and Rebudgeting as at 07_10_09 XP
version.xls]/Monthly Detailed P&L

No other details in the links change (i.e. locations like the folder names,
worksheet name and cell etc are in exactly the same place in the new workbook
so they don't need to change)

Current code:

Sub Replace()
Dim WS As Worksheet

Application.ScreenUpdating = False
Application.DisplayAlerts = False

For Each WS In Worksheets
WS.Cells.Replace What:=InputBox("Enter prior workbook words to be replaced
in links"), Replacement:=InputBox("Enter new workbook words to be entered
into links"), _
LookAt:=xlPart, SearchOrder:=xlByColumns, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub


--
Thank for your help in Advance
BeSmart
 
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
replace special character for filename save anduare2 Excel Programming 10 April 21st 08 03:12 PM
Find/Replace Event or Find/Replace for Protected Sheet ... Joe HM Excel Programming 2 October 27th 07 03:55 PM
Replace first 8 letters of filename with Macro [email protected] Excel Programming 5 February 21st 06 03:51 PM
Formula to replace invalid filename characters tschultz Excel Worksheet Functions 2 January 27th 06 07:07 PM
Set Location and Filename to replace GetOpenFilename David Excel Programming 3 June 1st 05 02:29 PM


All times are GMT +1. The time now is 08:06 AM.

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"