Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2018, 09:51 AM
puff puff is offline Macro to insert an image based as told Windows 7 64bit Macro to insert an image based as told Office 2013
Advanced Beginner
Macro to insert an image based as told
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Question Macro to insert an image based as told


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~
Reply With Quote
  #2  
Old 05-24-2018, 03:55 PM
macropod's Avatar
macropod macropod is offline Macro to insert an image based as told Windows 7 64bit Macro to insert an image based as told Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to insert an image based as told insert Image ?? Jazz Outlook 1 09-10-2015 04:34 AM
Macro to insert an image based as told Word VBA Macro to Find and Replace based on the Alt Text of an Image bennymc Word VBA 1 01-27-2014 04:23 PM
Macro to insert an image based as told Insert image based on document custom property 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:59 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft