ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel - Word (Textbox Find/Replace) (https://www.excelbanter.com/excel-programming/446505-excel-word-textbox-find-replace.html)

aiwnjoo

Excel - Word (Textbox Find/Replace)
 
Hi guys, really struggling here and tried on different forums but nobody seems equipped to resolve this so fingers crossed that there is a genius amongst us :)

Current Macro, this is fully working for non-textbox find/replace however i need a version of this that supports textboxes.

Code:

Sub Replacing()


    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Cursor = xlWait
    Application.DisplayStatusBar = True
    Application.StatusBar = "Generating DM Pack, please wait!"
   
    On Error GoTo 0
   
    Dim sFile    As String
    Dim wrdApp    As Word.Application
    Dim wrdDoc    As Word.Document
    Dim sInput(0) As String, sOutput(0) As String


    sFile = "KF"
   
    Set wrdApp = New Word.Application


    With wrdApp
   
        .Visible = True
       
    Set wrdDoc = .Documents.Open("C:\Docs\" + sFile + ".doc")
   
    .Selection.Find.ClearFormatting
    .Selection.Find.Replacement.ClearFormatting
   
    sInput(0) = "Test"
   
    sOutput(0) = "ACCREF"
   
   
    For i = 0 To UBound(sInput) - 1
   
      With .Selection.Find
        .Text = sOutput(i)
        .Replacement.Text = Range(sInput(i)).Text
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
       
    End With
   
    Next

Thanks,


All times are GMT +1. The time now is 10:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com