Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2012, 01:05 AM
krishnaoptif krishnaoptif is offline replace data from variable with "sub and super script" from excel to word by vba Windows XP replace data from variable with "sub and super script" from excel to word by vba Office 2007
Novice
replace data from variable with "sub and super script" from excel to word by vba
 
Join Date: May 2012
Posts: 23
krishnaoptif is on a distinguished road
Default

Mr Paul,



Now my logic has been chaged... if any text replaced is one time in document then will be red and if more then one time then that will be yellow for all..... this is in my code i think you did not see that...

Your This code is working like my first logic for the red and yeallow color...and also there is some format issue in your code in my ms word line three text "probability of deletion (Pd)"

Now i have apply you code in my doc VBA project....

Pelase check the attached files and run...then you will find the line three problm and color code change...

and Third logic is which used in my code.... if text is

Visual Basic (VBA) in MS word and i have to change Visual Basic to VBA then it will be after replace
VBA (VBA)

but i need only one VBA... so if it is VBA (VBA) then again should be replace by VBA only..

Then final result is

VBA
Attached Files
File Type: doc Command_New_New.doc (56.0 KB, 10 views)
File Type: xls Excel Data.xls (39.5 KB, 9 views)
Reply With Quote
  #2  
Old 06-22-2012, 02:31 AM
macropod's Avatar
macropod macropod is offline 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,502
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

Quote:
Originally Posted by krishnaoptif View Post
Now my logic has been chaged... if any text replaced is one time in document then will be red and if more then one time then that will be yellow for all
In that case, you could swap 'wdYellow' and 'wdRed' and change 'If iCount > 1 Then' to 'If iCount = 1 Then'
Quote:
there is some format issue in your code in my ms word line three text "probability of deletion (Pd)"
The simplest way to deal with with is to take a completely different approach. Try:
Code:
Application.ScreenUpdating = False
Dim lRow As Long, lTbl As Long
Dim RngFnd As Range, RngRep As Range, RngSrch As Range
Dim StrFnd As String, StrRep As String, StrSrch As String
With SrcWb
  SrcWs.UsedRange.Copy
  .Close False
End With
DoEvents
Set SrcWs = Nothing: Set SrcWb = Nothing
With ThisDocument
  .Range.InsertAfter vbCr
  .Characters.Last.Paste
  DoEvents
  lTbl = .Tables.Count
  Set RngSrch = .Range(0, .Tables(lTbl).Range.Start)
  For lRow = 2 To .Tables(lTbl).Rows.Count
    Set RngFnd = .Tables(lTbl).Rows(lRow).Cells(1).Range
    RngFnd.End = RngFnd.End - 1
    StrFnd = Trim(RngFnd.Text)
    Set RngRep = .Tables(lTbl).Rows(lRow).Cells(2).Range
    RngRep.End = RngRep.End - 1
    RngRep.Copy
    StrRep = Trim(RngRep.Text)
    Application.Options.DefaultHighlightColorIndex = wdRed
    With RngSrch.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Format = False
      .MatchCase = False
      .MatchWholeWord = True
      .Wrap = wdFindContinue
      .Text = StrFnd & "^w(" & StrRep & ")"
      .Replacement.Text = StrFnd
      .Execute Replace:=wdReplaceAll
      .Text = StrFnd
      .Replacement.Text = "^c"
      .Replacement.Highlight = True
      .Execute Replace:=wdReplaceAll
    End With
    StrSrch = RngSrch.Text
    If (Len(StrSrch) - Len(Replace(StrSrch, StrRep, ""))) / Len(StrRep) = 1 Then
      Application.Options.DefaultHighlightColorIndex = wdYellow
      With RngSrch.Find
        .Text = StrRep
        .Replacement.Text = "^&"
        .Highlight = True
        .Replacement.Highlight = True
        .Wrap = wdFindContinue
        .Execute Replace:=wdReplaceOne
      End With
    End If
  Next
  .Tables(lTbl).Delete
  .Characters.Last.Delete
End With
Set RngSrch = Nothing: Set RngFnd = Nothing: Set RngRep = Nothing
Application.ScreenUpdating = True
MsgBox "Done"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
replace data from variable with "sub and super script" 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 "sub and super script" 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 10:14 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