Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-31-2022, 05:49 AM
macropod's Avatar
macropod macropod is offline VBA to replace a repeated single variable with variable from a list Windows 10 VBA to replace a repeated single variable with variable from a list Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For example:


Code:
Sub DemoB()
Application.ScreenUpdating = False
Dim StrVAR1 As String, StrVAR2 As String, i As Long, j As Long
StrVAR1 = "red|white|blue"
StrVAR2 = "dot|star|check"
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Wrap = wdFindContinue
  .MatchWildcards = True
  For i = 0 To UBound(Split(StrVAR1, "|"))
    For j = 0 To UBound(Split(StrVAR2, "|"))
      .Text = "<VAR1>"
      .Replacement.Text = Split(StrVAR1, "|")(i)
      .Execute Replace:=wdReplaceOne
      .Text = "<VAR2>"
      .Replacement.Text = Split(StrVAR2, "|")(j)
      .Execute Replace:=wdReplaceOne
   Next
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to create a bar chart of multiple variable. Then I need to draw trend lin of those variable shimulsiddiquee Excel 1 05-16-2017 07:39 AM
VBA to replace a repeated single variable with variable from a list ord vba replace the variable text with variable images to make offer products with images tanzinim Word VBA 4 12-30-2015 01:40 PM
Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge Berryblue Mail Merge 1 11-13-2014 05:36 PM
VBA to replace a repeated single variable with variable from a list Run-time error 91 object variable or with block variable not set JUST ME Word VBA 4 03-25-2014 06:56 AM
VBA to replace a repeated single variable with variable from a list Run-time error '91': Object variable or With block variable not set tinfanide Excel Programming 2 06-10-2012 10:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:28 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