Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 12-10-2015, 04:55 AM
gmayor's Avatar
gmayor gmayor is offline How to display a message box if a box is selected Windows 7 64bit How to display a message box if a box is selected Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

It is better to avoid using the Selection object - especially if the bookmark is in a header, and as you may have realised you can simply call the message box from your code. The following uses a function to write to the bookmark and reset the bookmark to the new text, so it is easy to replace or remove the text. The bookmarks are accessed by name.

Code:
Sub chkVisa_Click()
    If Me.chkVisa = True Then
        FillBM "VisaHeader", "28. Visa Sponsorship"
        FillBM "VisaText", "As an employee from outside the European Union you will require to have a company sponsored visa before commencing employment. The company will work with an appointed immigration specialist to ensure the correct clearance to work in the United Kingdom."
        FillBM "VisaText2", "On completion of your probationary period, were you to leave the company within 24 months of your visa start date you will be required to pay back a percentage of the costs associated with obtaining the company sponsorship visa."
    Else
        FillBM "VisaHeader", ""
        FillBM "VisaText", ""
        FillBM "VisaText2", ""
    End If
    MsgBox "Hello"
End Sub

Private Sub FillBM(strBMName As String, strValue As String)
'Graham Mayor
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        oRng.Text = strValue
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem opening Outlook Today. Error Message: Cannot display the folder. Cannot find this file. Veri atwnsw Outlook 0 11-01-2015 05:05 PM
How to Display Arrow for Drop Down Lists in Message Body hue2 Outlook 0 03-20-2015 12:24 PM
Pivot Table Question- Can the table display in the order the boxes were checked/selected? blackjack Excel 0 09-13-2014 08:57 PM
Option Button selected will display text ksigcajun Word VBA 7 07-14-2014 09:31 AM
Display paragraph of text based on value selected in combo WordWaza Word 0 08-09-2013 06:30 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:34 PM.


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