![]() |
#1
|
|||
|
|||
![]() Hi all. I have a bunch of images to be inserted in a document. Rather than using the menu of the insert, can I write in the document like [insert image 1] and then use a macro to insert the first image in a folder designated and so on? I cannot insert all the images altogether because they need to be in their specific place mixed with the text. Thank you~ |
#2
|
||||
|
||||
![]()
You could but, by the time you've found & inserted the image name, you've probably spent nearly as much time as you would inserting the image. The following macro assumes the text between the square brackets is the image name, including the file extension (e.g. [ScreenShot1.png])
Code:
Sub InsertPics() Application.ScreenUpdating = False Dim strFolder As String, strFile As String strFolder = GetFolder If strFolder = "" Then Exit Sub With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "\[[!\[]@\]" .Replacement.Text = "" .Format = False .Forward = True .Wrap = wdFindStop .MatchWildcards = True .Execute End With Do While .Find.Found strFile = Trim(Replace(Replace(.Duplicate.Text, "[", ""), "]", "")) If Dir(strFolder & "\" & strFile) <> "" Then .InlineShapes.AddPicture strFolder & "\" & strFile, False, True, .Duplicate End If .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Jazz | Outlook | 1 | 09-10-2015 04:34 AM |
![]() |
bennymc | Word VBA | 1 | 01-27-2014 04:23 PM |
![]() |
anandyrh | Word | 1 | 08-14-2013 12:08 AM |
MACRO - Insert row based on Form Field Criteria | Elan05 | Word VBA | 5 | 04-16-2013 06:39 AM |
Background image vs. insert image | lilaria | PowerPoint | 0 | 04-18-2011 08:45 AM |