Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2015, 03:35 AM
pisolino pisolino is offline Vba Word multiple images at bookmarks Windows 10 Vba Word multiple images at bookmarks Office 2013
Novice
Vba Word multiple images at bookmarks
 
Join Date: Sep 2015
Posts: 5
pisolino is on a distinguished road
Talking Vba Word multiple images at bookmarks

Hi all,

As part of my work, I need to insert 4 images at 4 different bookmarked places.
I use template so i always have bm1, bm2, bm3 and bm4 as my bookmarked places where my images should be, but the problem is that everytime i generate new document my images names should change 2.
For example...


In document1 my image names are foto-1 it goes to bm1, image-1 goes to bm2, pic-1 goes to bm3 and icon-1 goes to bm4.
But for document2 all pics are now foto-2, image-2 and so on.
Is there way to create macro that every time it fills all 4 images at bookmarked places create new documents that insert second set of images into and goes on until it insert all images.

Thank you if some1 has the answer i would appreciate it very much.
Reply With Quote
  #2  
Old 09-14-2015, 04:09 AM
gmayor's Avatar
gmayor gmayor is offline Vba Word multiple images at bookmarks Windows 7 64bit Vba Word multiple images at bookmarks Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I may have misunderstood the requirement, but take a look at http://www.gmayor.com/photo_gallery_template.html which should do what you require.

If I have misunderstood, or the format of your template doesn't allow it the use of such a gallery, then a vba process to loop through your graphics, and create a new document from the template every 4 graphics and add them to bookmarked locations is relatively simple to achieve. What is less clear is what you mean about the image names?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 09-14-2015, 04:33 AM
pisolino pisolino is offline Vba Word multiple images at bookmarks Windows 10 Vba Word multiple images at bookmarks Office 2013
Novice
Vba Word multiple images at bookmarks
 
Join Date: Sep 2015
Posts: 5
pisolino is on a distinguished road
Default

Thank you sou much for quick reply.

I ment that images have been named incrementally at all 4 places (e.g.: 010.jpg, 011.jpg, and so on.
Reply With Quote
  #4  
Old 09-14-2015, 04:58 AM
gmayor's Avatar
gmayor gmayor is offline Vba Word multiple images at bookmarks Windows 7 64bit Vba Word multiple images at bookmarks Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will put the selected graphics at your bookmarks, four to a document.
Put all the code in the same new module
Code:
Option Explicit

Sub InsertImages()
'Graham Mayor
Const strFile As String = "C:\Path\ImageTemplate.docx"        'The template
Dim oBM As Bookmark
Dim oDoc As Document
Dim vImages As Variant
Dim i As Long
    vImages = Split(BrowseForFiles, Chr(124))
    On Error GoTo err_Handler
    For i = LBound(vImages) To UBound(vImages) Step 4
        Set oDoc = Documents.Add(strFile)
        ImageToBM "bm1", CStr(vImages(i))
        ImageToBM "bm2", CStr(vImages(i + 1))
        ImageToBM "bm3", CStr(vImages(i + 2))
        ImageToBM "bm4", CStr(vImages(i + 3))
    Next i
lbl_Exit:
    Exit Sub
err_Handler:
    GoTo lbl_Exit
End Sub

Private Function BrowseForFiles(Optional strTitle As String) As String
'Graham Mayor
'strTitle is the title of the dialog box
Dim fDialog As FileDialog
Dim i As Long
    On Error GoTo err_Handler
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = strTitle
        .AllowMultiSelect = True
        .Filters.Clear
        .Filters.Add "Image Files", "*.jpg,*.png,*.tif,*.bmp,*.gif"
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo err_Handler:
        BrowseForFiles = ""
        For i = 1 To fDialog.SelectedItems.Count
            BrowseForFiles = BrowseForFiles & fDialog.SelectedItems(i)
            If i < fDialog.SelectedItems.Count Then
                BrowseForFiles = BrowseForFiles & Chr(124)
            End If
        Next i
    End With
lbl_Exit:
    Exit Function
err_Handler:
    BrowseForFiles = vbNullString
    Resume lbl_Exit
End Function

Private Sub ImageToBM(strBMName As String, strValue As String)
'Graham Mayor
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        oRng.InlineShapes.AddPicture _
                Filename:=strValue, LinkToFile:=False, _
                SaveWithDocument:=True
        oRng.End = oRng.End + 2
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 09-14-2015, 05:24 AM
pisolino pisolino is offline Vba Word multiple images at bookmarks Windows 10 Vba Word multiple images at bookmarks Office 2013
Novice
Vba Word multiple images at bookmarks
 
Join Date: Sep 2015
Posts: 5
pisolino is on a distinguished road
Thumbs up

Works perfect.

Thk u so much .

U saved my day
Reply With Quote
  #6  
Old 09-14-2015, 09:16 AM
pisolino pisolino is offline Vba Word multiple images at bookmarks Windows 10 Vba Word multiple images at bookmarks Office 2013
Novice
Vba Word multiple images at bookmarks
 
Join Date: Sep 2015
Posts: 5
pisolino is on a distinguished road
Default

Need help again thx in advance

For i = LBound(vImages) To UBound(vImages) Step 4
Set oDoc = Documents.Add(strFile)
ImageToBM "bm1", CStr(vImages(i))
ImageToBM "bm2", CStr(vImages(i + 1))
ImageToBM "bm3", CStr(vImages(i + 2))
ImageToBM "bm4", CStr(vImages(i + 3))
Next i

So now my 4 images I need to insert are called 1393_1_FOTO,1393_1_PHOTO,
1393_1_ST, 1393_1_DS for point number 1.
For point number 2 are 1393_2_FOTO,1393_2_PHOTO,
1393_2_ST, 1393_2_DS.
So everything stays the same except middle number which is always rising +1 for every point. So i would like a macro that asks me point number and when i write point number it links to image middle number like above and inserts them at bookmarked places bm1,bm2,bm3 and bm4.
Reply With Quote
  #7  
Old 09-16-2015, 03:03 AM
pisolino pisolino is offline Vba Word multiple images at bookmarks Windows 10 Vba Word multiple images at bookmarks Office 2013
Novice
Vba Word multiple images at bookmarks
 
Join Date: Sep 2015
Posts: 5
pisolino is on a distinguished road
Default

http://www.vbaexpress.com/forum/show...value&p=330779

for more answers
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking Combobox to multiple bookmarks scarda Word VBA 4 01-20-2015 10:48 PM
Vba Word multiple images at bookmarks Form updating Bookmarks - writes to the bookmarks multiple times PeterPlys Word VBA 13 01-14-2015 06:41 AM
Preview multiple images midjack Outlook 0 10-18-2014 08:35 AM
Vba Word multiple images at bookmarks VBA code to extract specific bookmarks from multiple word files Rattykins Word VBA 4 06-27-2012 10:02 PM
Vba Word multiple images at bookmarks Multiple Background Images in MS Word 07 Mark Drawing and Graphics 3 05-06-2009 08:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:38 PM.


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