'Links Used by Chirayu Walawalkar:
'http://stackoverflow.com/questions/11564857/how-do-i-get-the-current-filename-of-a-word-document-without-the-extension-or-f
'http://word.tips.net/T000819_Determining_if_a_File_Exists.html
'http://word.tips.net/T001437_Batch_Template_Changes.html
Function FileThere(FileName As String) As Boolean
FileThere = (Dir(FileName) > "")
End Function
'===
Sub Case_Image()
'loop to work on all files
Dim strDocPath As String
Dim strCurDoc As String
Dim docCurDoc As Document
strDocPath = "C:\Cases\" '>>>>> change folder path if cases stored in different folder
strCurDoc = Dir(strDocPath & "*.doc") '>>>>> check if doc or docx and change accordingly
Do While strCurDoc <> ""
Set docCurDoc = Documents.Open(FileName:=strDocPath & strCurDoc)
'get my document name without .doc/.docx and other extensions
Dim doc As String
If InStrRev(ActiveDocument.Name, ".") <> 0 Then
doc = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1)
Else
doc = ActiveDocument
End If
'check if my image exists and matches my document name
'if image found then add new page and copy image
If FileThere(ActiveDocument.Path & "\images\" & doc & ".jpg") Then '>>>>> relates to the function written above
Selection.InsertNewPage
Selection.InlineShapes.AddPicture FileName:= _
ActiveDocument.Path & "\images\" & doc & ".jpg", _
LinkToFile:=False, SaveWithDocument:=True
'if image not found then give me a message saying that
Else
'''''MsgBox "Image not found", vbInformation, ""
End If
'=====
docCurDoc.Close wdSaveChanges
' get next file name
strCurDoc = Dir
Loop
MsgBox "Folder consolidated", vbInformation, ""
End Sub