Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-06-2020, 07:21 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline vbYesNo, my script only acts on Yes, doesn't do anyting on No? Help Windows 10 vbYesNo, my script only acts on Yes, doesn't do anyting on No? Help Office 2013
Competent Performer
vbYesNo, my script only acts on Yes, doesn't do anyting on No? Help
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default vbYesNo, my script only acts on Yes, doesn't do anyting on No? Help

Hello,
I need help. Trying to figure out what the heck is wrong with my script.

I have an InputBox, to enter a text that I would find in a Word document.
So basicly, if I find a word among a sentence, I wish to be asked Yes or No, if I should delete it.

If I Click on Yes, it works fine, but if I click on No, it's stuck. That's it. I must do it on a dummy document to test it and must say Yes in order to stop the script.

Is there anyone that could guide me where is my script going wrong?

I'm also trying to encorporate vbYesNoCancel, but I don't know what to do, cause the button Cancel is there, but it doesn't act on it.

Sub Delete_Sentence_if_Word_found()
Dim strTexts As String
Dim oRng As range
Dim bFound As Boolean
bFound = False
strTexts = InputBox("Enter texts to be found here: ")
Set oRng = ActiveDocument.range
With oRng.Find
.ClearFormatting
.Text = strTexts
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
While .Execute
bFound = True
oRng.Expand Unit:=wdParagraph
oRng.Select
ActiveDocument.ActiveWindow.ScrollIntoView Selection.range, True


If MsgBox("Are you sure to delete the sentence?", vbYesNo) = vbYes Then
Selection.Delete
End If
oRng.Collapse wdCollapseEnd
Wend
End With
If Not bFound Then
End If
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
Reply With Quote
 

Tags
vbyesno help



Similar Threads
Thread Thread Starter Forum Replies Last Post
vbYesNo, my script only acts on Yes, doesn't do anyting on No? Help Script Directory charlesdh Excel Programming 3 06-12-2018 01:36 PM
vbYesNo, my script only acts on Yes, doesn't do anyting on No? Help Outlook VBA Script kcm5153 Outlook 1 04-07-2015 11:41 PM
Help with VBA script nsyrax Word VBA 1 01-18-2014 03:38 AM
the character "v" when typed acts like ctrl-v. jim redfield Word 1 09-22-2012 05:19 AM
vbYesNo, my script only acts on Yes, doesn't do anyting on No? Help Script Doesn't works on other machine ravininave Word 1 01-05-2011 01:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft