![]() |
#11
|
|||
|
|||
![]()
I've been playing around some more with this and rather than just inserting text sequentially into bookmarks I've trying to insert specific text into bookmarks based on particular criteria. In this case selecting pre written text in the form of bookmarks to produce a document tailored to whether the recipient status is either " Single", "Pair 1 or "Pair 2"
This seems to work OK for my learning needs but wondered if there was a more efficient way of writing the code because I'm guessing the way I have written it is probably not very elegant and would lead you to suspect I was 5 years old ![]() Sub BookmarkUpdate2() Dim oBMRng As Range Dim lngIndex As Long Dim BMcnt As Long Dim Status As String Dim z As Long Dim x As Long For BMcnt = 1 To 4 'Loop through Bookmarks x = 1 'Change to simulate Status either 1 = Single. 2 = Pair 1 or 3 =Pair 2 If x = 1 Then Status = "Single" If x = 2 Then Status = "Pair 1" If x = 3 Then Status = "Pair 2" If BMcnt = 1 And Status = "Single" Then z = 1 ElseIf BMcnt = 1 And Status <> "Single" Then z = 2 ElseIf BMcnt = 2 And Status <> "Pair 2" Then z = 3 ElseIf BMcnt = 2 And Status = "Pair 2" Then z = 4 ElseIf BMcnt = 3 And Status = "Single" Then z = 8 ElseIf BMcnt = 3 And Status <> "Single" Then z = 5 ElseIf BMcnt = 4 And Status <> "Pair 1" Then z = 6 ElseIf BMcnt = 4 And Status = "Pair 1" Then z = 7 End If lngIndex = z Set oBMRng = ActiveDocument.Bookmarks("MyBookmark" & BMcnt).Range Select Case lngIndex Case 1: oBMRng.Text = "You have been assigned to Team <<TeamNo>>. Usually you would be paired with another team, however at this time no suitable pairing has been identified" Case 2: oBMRng.Text = "You have been assigned to Team <<TeamNo >> and paired with: <<PairedWithTeam>>." & vbNewLine & "Their contact details are as follows: " & vbNewLine & "<<TheirName>>" & vbNewLine & "<<TheirPhone>>" & vbNewLine & "<<TheirEmail>>" Case 3: oBMRng.Text = "The equipment will be delivered to <<YourTeam>> on <<DeliveryDate>>." Case 4: oBMRng.Text = "The equipment will be delivered to <<PairedWithTeam>> on <<DeliveryDate>>." Case 5: oBMRng.Text = "The equipment is then exchanged between yourselves and <<PairedWithTeam>> on alternate weeks over a 6-week period." Case 6: oBMRng.Text = "The equipment will then be collected from <<YourTeam>> on <<CollectionDate>>." Case 7: oBMRng.Text = "The equipment will then be collected from <<PairedWithTeam>> on <<CollectionDate>>." Case 8: oBMRng.Text = "" End Select 'Re-insert the bookmark ActiveDocument.Bookmarks.Add "MyBookmark" & BMcnt, oBMRng 'Next lngIndex Next BMcnt lbl_Exit: Exit Sub End Sub Last edited by RedZed1100; 08-26-2020 at 06:08 AM. Reason: Typing errors |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replacing text held in all bookmarks | THH4929 | Word VBA | 6 | 06-02-2018 04:29 AM |
![]() |
lvganesh | Word VBA | 5 | 12-12-2017 11:27 PM |
![]() |
adilprodigy | Word VBA | 1 | 10-11-2017 01:31 PM |
Macro to hide/unhide text to call variable bookmarks | Dr. Z | Word VBA | 2 | 05-27-2017 08:20 PM |
![]() |
PeterPlys | Word VBA | 13 | 01-14-2015 06:41 AM |