Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Replace object causes an error if search text not found

Hello!

I have an issue that doesn't seem like it would be a big deal, but it is
causing major headaches. I should say that I am using Excel 2003:

What I need to do is have a standard Excel document that a user can modify
to include text that will be replaced with information from a database. This
works great currently. How I do it, is the user will place the field code as
a string in the body of a template Excel template (for example: person_name).
When the user clicks a button in my ASP page, I call the File System Object
and copy the template document to a location on the server. This works great!

Now, I want to replace the string in the copied document with that of a
field value as generated from the ASP page. This works great also!

I want to allow the user to add or remove strings from the Excel template as
they see fit, but currently, if they remove a field from the template, it is
obviously not available in the copied document as outlined above. This causes
an error!!!! i.e. if the replacement text is not in the Excel workbook, my
code will progress no further! I have tried to use .EnableEvents = False but
this doesn't work either.

What I need it to do is if it doesn't find the search string, to just move
on. Here is some partial code (its in JScript but I converted it here to
VBScript):

Set objRange = xlApp.ActiveWorkbook.Worksheets(w).UsedRange
objRange.Select
objRange.Replace( strFindText, strReplaceText)

--


Thanks!

Scott
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Replace object causes an error if search text not found

XL2002 and above returns an alert if nothing is found to replace. Try
disabling the alerts...

application.displayalerts = false
objRange.Replace( strFindText, strReplaceText)
application.displayalerts = true
--
HTH...

Jim Thomlinson


"Scott" wrote:

Hello!

I have an issue that doesn't seem like it would be a big deal, but it is
causing major headaches. I should say that I am using Excel 2003:

What I need to do is have a standard Excel document that a user can modify
to include text that will be replaced with information from a database. This
works great currently. How I do it, is the user will place the field code as
a string in the body of a template Excel template (for example: person_name).
When the user clicks a button in my ASP page, I call the File System Object
and copy the template document to a location on the server. This works great!

Now, I want to replace the string in the copied document with that of a
field value as generated from the ASP page. This works great also!

I want to allow the user to add or remove strings from the Excel template as
they see fit, but currently, if they remove a field from the template, it is
obviously not available in the copied document as outlined above. This causes
an error!!!! i.e. if the replacement text is not in the Excel workbook, my
code will progress no further! I have tried to use .EnableEvents = False but
this doesn't work either.

What I need it to do is if it doesn't find the search string, to just move
on. Here is some partial code (its in JScript but I converted it here to
VBScript):

Set objRange = xlApp.ActiveWorkbook.Worksheets(w).UsedRange
objRange.Select
objRange.Replace( strFindText, strReplaceText)

--


Thanks!

Scott

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
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
search function without error if not found anderssweden Excel Programming 1 June 14th 06 03:38 PM
Return text found in a search Dave R. Excel Worksheet Functions 4 May 12th 05 08:53 PM
The search key was not found error Nydia New Users to Excel 0 April 27th 05 03:09 PM
Search column - return row found in long text string JayL Excel Programming 1 March 5th 05 03:23 AM


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