Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2021, 10:38 AM
laith93 laith93 is offline Searching in main body document and text boxes at the same time Windows 10 Searching in main body document and text boxes at the same time Office 2019
Competent Performer
Searching in main body document and text boxes at the same time
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Post Searching in main body document and text boxes at the same time


Hi,
This code was developed by Doug Robbins - MVP
Code:
Sub FormatScientificNamesByExcel()

Dim xlApp As Object
Dim xlbook As Object
Dim xlsheet As Object
Dim MyArray As Variant
Dim FD As FileDialog
Dim strSource As String
Dim i As Long, lognum As Long

Set FD = Application.FileDialog(msoFileDialogFilePicker)

With FD

.Title = "Select the workbook that contains the terms to be italicized"

.Filters.Clear

.Filters.Add "Excel Workbooks", "*.xlsx"

.AllowMultiSelect = False

If .Show = -1 Then

strSource = .SelectedItems(1)

Else

MsgBox "You did not select the workbook that contains the data"

Exit Sub

End If

End With

On Error Resume Next

Set xlApp = GetObject(, "Excel.Application")

If Err Then

bstartApp = True

Set xlApp = CreateObject("Excel.Application")

End If

On Error GoTo 0

Set xlbook = xlApp.Workbooks.Open(strSource)

Set xlsheet = xlbook.Worksheets(1)

MyArray = xlsheet.range("A1").CurrentRegion.Value

If bstartApp = True Then

xlApp.Quit

End If

Set xlApp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing

For i = LBound(MyArray) To UBound(MyArray)

Selection.HomeKey wdStory

Selection.Find.ClearFormatting

With Selection.Find

Do While .Execute(findText:=MyArray(i, 1), Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True

Set Rng = Selection.range

Selection.Collapse wdCollapseEnd

Rng.Font.Italic = True

Loop

End With

Next i

End Sub
This code searches for text (that is already present in the excel file), and changes the formatting of the founded text in the word file to italic.

The code works fine, but the only problem is searching in the main body document only, and it ignores the text in text boxes

Hence, I want to include text boxes also in searching

Mr. Andrew, I want your help please, as you fixed my problem in this post (same idea):
https://www.msofficeforums.com/163297-post20.html
if not possible with this code, any other codes to do my requirement?

You can download the sample and excel file in the attachment to apply on it.
Thank you
Attached Files
File Type: docx Sample.docx (23.4 KB, 6 views)
File Type: xlsx MicrobialNameDatabase.xlsx (11.0 KB, 6 views)
Reply With Quote
Reply

Tags
find and replace, vba change textbox word, word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic link creation, after writing: Link text in main body (multiple instances) mike_302 Word VBA 2 07-05-2021 12:28 AM
Searching in main body document and text boxes at the same time How do I lock an editable text box header and stop it moving with the rest of the main body text? thegaffa Word 6 09-28-2018 09:21 AM
Searching in main body document and text boxes at the same time How do I get equal space between main body text and footnote separator line on every page? Different Word 1 02-09-2015 09:15 PM
keyboard shortcut to shift focus from comment to main body of doc randomonia Word 4 05-16-2013 03:28 PM
Searching in main body document and text boxes at the same time Mail merger with different template/main body text RPM7 Mail Merge 1 04-27-2010 07:20 AM

Other Forums: Access Forums

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