![]() |
|
|
|
#1
|
|||
|
|||
|
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
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 |
|
| 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 |
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 |
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 |
Mail merger with different template/main body text
|
RPM7 | Mail Merge | 1 | 04-27-2010 07:20 AM |