VBA

Moderators: PavlinII
Number of threads: 1673
Number of posts: 3078

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: I need to suppress the "results not found" messagebox Posted by MrXmas on 26 Sept 2005 at 9:52 AM
Nevermind. Found it:

doc.Application.DisplayAlerts = False turns them off.



: Did you ever find a solution to this problem?
:
: I'm facing the exact same problem. This is code that ran fine in older versions of Excel, but now crashes because of the message box in Excel 2003.
:
: Thanks,
:
:
: : The following subroutine finds and replace occurances of a string in an xls file; the code works find in its task, however, when it finds no results it prompts the user. I don't want it to do that- any ideas?
: : Thanks.
: :
: : Sub excelReplace(filename As String, searchString As String, replacement As String)
: :
: : On Error GoTo ErrorHandler
: :
: : Dim doc As Excel.Application
: : Set doc = CreateObject("Excel.Application")
: : doc.Workbooks.Open (filename)
: : 'Dim found As Boolean
: : Dim currentSheet As Worksheet
: :
: : For Each currentSheet In doc.Worksheets
: : currentSheet.Cells.Replace(What:=searchString, replacement:=replacement, LookAt:=xlPart, SearchOrder _
: : :=xlByRows, MatchCase:=chkMatchCase.Value, SearchFormat:=False, ReplaceFormat:=False)
: : Next
: :
: : Dim currentWorkbook As workbook
: :
: : For Each currentWorkbook In doc.Workbooks
: : currentWorkbook.Save
: : Next currentWorkbook
: :
: : Call doc.Workbooks.Close
: : Set doc = Nothing
: : Exit Sub
: :
: : ErrorHandler:
: :
: : Call MsgBox("An Error Occured:" & Chr(13) & Chr(13) & "Error Number : " & Err.Number & Chr(13) & Chr(13) & Err.Description, vbOKOnly + vbCritical, "Error")
: : Err.Clear
: :
: : End Sub
: :
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.