Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2018, 10:24 PM
crazzyapple crazzyapple is offline Word VBA - Ignore MsgBox Windows 7 64bit Word VBA - Ignore MsgBox Office 2010
Novice
Word VBA - Ignore MsgBox
 
Join Date: Nov 2018
Posts: 2
crazzyapple is on a distinguished road
Default Word VBA - Ignore MsgBox

Hi;




I am using MS Word 2016 and I am trying to ignore a MsgBox, if the button is already deleted. This Sub is being called in another Sub. How the code is now, the message will always show. Any help will be greatly appreciated.



Code:
Sub DeleteButton()
Dim obj As Object
Dim varResponse As Variant

 varResponse = MsgBox("Button will be deleted.")
 
For Each obj In ActiveDocument.InlineShapes
 If varResponse = vbOK Then
    
  If obj.OLEFormat.Object.Name = "CommandButton1" Then
        obj.Delete
        
  End If
  End If
 Next
 
End Sub
Reply With Quote
  #2  
Old 11-07-2018, 11:11 PM
gmayor's Avatar
gmayor gmayor is offline Word VBA - Ignore MsgBox Windows 10 Word VBA - Ignore MsgBox Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Move the message box to where you need to ask the question e.g.


Code:
Sub DeleteButton()
Dim obj As Object
Dim varResponse As Variant

    For Each obj In ActiveDocument.InlineShapes
        If obj.OLEFormat.Object.Name = "CommandButton1" Then
            varResponse = MsgBox("Button will be deleted.")
            If varResponse = vbOK Then obj.Delete
        End If
    Next
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-08-2018, 12:06 AM
crazzyapple crazzyapple is offline Word VBA - Ignore MsgBox Windows 7 64bit Word VBA - Ignore MsgBox Office 2016
Novice
Word VBA - Ignore MsgBox
 
Join Date: Nov 2018
Posts: 2
crazzyapple is on a distinguished road
Default

thank you gmayor
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA - Ignore MsgBox Problem with Msgbox in VBA Puzzled Programmer Excel Programming 6 09-06-2018 04:34 PM
msgbox when deleting cells Mikedk64 Excel Programming 11 07-13-2017 07:14 AM
What happend to Ignore once (spell check) in Word 2013? nick93 Word 2 07-05-2016 01:44 PM
How to make word ignore a specific shape when printing? ZAK Word 12 04-07-2014 03:14 PM
Word VBA - Ignore MsgBox Make MsgBox appear... Jamtart PowerPoint 3 09-01-2012 08:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:14 AM.


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