Programmer_n
03-08-2020, 03:57 AM
My intention is to add images from a folder to a new document if the name of the images occur within a word document.
So workflow is check the document against a list and emphasize the word and check emphasized words against image name and add those images to a new word document if it matches. the image name could be single word or multiple words.
For example a folder contains two images one named 'galleries' and another named 'document building blocks' document exactly stored within a folder.
' Now I have stored this words in a word file called emphasis.docx and check its occurence within a word document.
The following macro checks the wordlist and italize the word below.
Although this step is insignificant it helps me see what words are being picked.
On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.
Sub H_emphasis()
Application.ScreenUpdating = False 'close screen and refresh
Dim StartTime As Double
Dim SecondsElapsed As Double
StartTime = Timer
Dim sCheckDoc As String
Dim docRef As Document
Dim docCurrent As Document
Dim oRng As range
Dim oPara As Paragraph
sCheckDoc = "D:\emphasis.docx"
Set docCurrent = ActiveDocument
Set docRef = Documents.Open(sCheckDoc)
docCurrent.Activate
For Each oPara In docRef.Paragraphs
Set oRng = oPara.range
oRng.End = oRng.End - 1
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Italic = True
.Replacement.Text = "^&"
.Forward = True
.Format = True
.MatchWholeWord = True
.MatchCase = False
.MatchWildcards = False
.Wrap = wdFindContinue
.Text = Trim(oRng.Text)
.Execute Replace:=wdReplaceAll
End With
Next oPara
docRef.Close
docCurrent.Activate
Application.ScreenUpdating = True
SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "ITALIZIED emphasis in " & SecondsElapsed & " seconds", vbInformation
End Sub
Now it is the step 2 I am uncertain? How to let word know pick galleries and document building blocks .jpeg and add those images to a new word document from lot of images in a folder. Please help me with this missing link in this work flow.
So workflow is check the document against a list and emphasize the word and check emphasized words against image name and add those images to a new word document if it matches. the image name could be single word or multiple words.
For example a folder contains two images one named 'galleries' and another named 'document building blocks' document exactly stored within a folder.
' Now I have stored this words in a word file called emphasis.docx and check its occurence within a word document.
The following macro checks the wordlist and italize the word below.
Although this step is insignificant it helps me see what words are being picked.
On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.
Sub H_emphasis()
Application.ScreenUpdating = False 'close screen and refresh
Dim StartTime As Double
Dim SecondsElapsed As Double
StartTime = Timer
Dim sCheckDoc As String
Dim docRef As Document
Dim docCurrent As Document
Dim oRng As range
Dim oPara As Paragraph
sCheckDoc = "D:\emphasis.docx"
Set docCurrent = ActiveDocument
Set docRef = Documents.Open(sCheckDoc)
docCurrent.Activate
For Each oPara In docRef.Paragraphs
Set oRng = oPara.range
oRng.End = oRng.End - 1
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Italic = True
.Replacement.Text = "^&"
.Forward = True
.Format = True
.MatchWholeWord = True
.MatchCase = False
.MatchWildcards = False
.Wrap = wdFindContinue
.Text = Trim(oRng.Text)
.Execute Replace:=wdReplaceAll
End With
Next oPara
docRef.Close
docCurrent.Activate
Application.ScreenUpdating = True
SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "ITALIZIED emphasis in " & SecondsElapsed & " seconds", vbInformation
End Sub
Now it is the step 2 I am uncertain? How to let word know pick galleries and document building blocks .jpeg and add those images to a new word document from lot of images in a folder. Please help me with this missing link in this work flow.