Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 06-21-2012, 11:23 PM
macropod's Avatar
macropod macropod is online now replace data from variable with "sub and super script" from excel to word by vba Windows 7 64bit replace data from variable with "sub and super script" from excel to word by vba Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
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

Try:
Code:
Dim iCount As Long, r As Long
Dim strSearch, strReplace As String
With SrcWs
  'Count the word
  r = 2
  strSearch = SrcWs.Cells(r, 1).Value
  While strSearch <> ""
    strReplace = SrcWs.Cells(r, 2).Value
    SrcWs.Cells(r, 2).Copy
    Application.Options.DefaultHighlightColorIndex = wdYellow
    With ThisDocument.Content
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Format = False
        .MatchCase = False
        .MatchWholeWord = True
        .Wrap = wdFindContinue
        .Text = strSearch & "^w(" & strReplace & ")"
        .Replacement.Text = strSearch
        .Execute Replace:=wdReplaceAll
        .Text = strSearch
        .Replacement.Text = "^c"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceOne
      End With
      While .Find.Found
        .Duplicate.Tables(1).ConvertToText Separator:=wdSeparateByTabs
        .Duplicate.Characters.Last.Delete
        .Find.Execute Replace:=wdReplaceOne
      Wend
    End With
    strSearch = ThisDocument.Range.Text
    iCount = (Len(strSearch) - Len(Replace(strSearch, strReplace, ""))) / Len(strReplace)
    If iCount > 1 Then
      Application.Options.DefaultHighlightColorIndex = wdRed
      With ThisDocument.Content.Find
        .Text = strReplace
        .Replacement.Text = "^&"
        .Highlight = True
        .Replacement.Highlight = True
        .Wrap = wdFindContinue
        .Execute Replace:=wdReplaceOne
      End With
    End If
    r = r + 1
    strSearch = SrcWs.Cells(r, 1).Value
  Wend
  SrcWb.Close False
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
replace data from variable with &quot;sub and super script&quot; from excel to word by vba How to "replace" a word with same word but "Italic"? Jamal NUMAN Word 4 07-08-2011 04:02 AM
replace data from variable with &quot;sub and super script&quot; from excel to word by vba How to use "if" to copy and paste data tareq Excel Programming 13 01-26-2011 03:34 PM
Rules and Alerts: "run a script"? discountvc Outlook 0 06-15-2010 07:36 AM
An "error has occurred in the script on this page" decann Outlook 8 09-03-2009 08:54 AM
Saving only "DATA" on excel? No white bottom? jrasche2003@yahoo.com Excel 0 08-07-2006 09:27 AM

Other Forums: Access Forums

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