Insert Pictures by file path in document for hundreds of pages that match common name MS Access VBA - vba

I have about 400 images that are in a separate directories by there name. I want to match these names with the filepath to the image attached to a report in access so the images will show up in access and I can print the report with the images included. I want to use VBA code as this is a repeating process and there are a lot of pages to insert a picture for otherwise done by hand.
I have some example data of my file paths. I have conditions.
I would like these images to show up in access so that they look like this when I export them. Here is an example. Each image from left to right will correspond to the trait 1,2,3 as shown in the table.
In access I have tried using hyperlink by I can't get it to match the Name to the name in the report like a master and child link or something in VBA might work too.
test3

Looks like this should be a two step process for you.
Add image placeholders. Insert an image where you want it on the report. Choose an image that would clearly show the image didn't load so you know when it's broken. Like a big red X.
Replace that image using an event that will load automatically as you make reports
EXAMPLE EVENT CODE:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me![Imageframe].Picture = Me![Imagepath]
End Sub
Replace the name of the Imageframe with whatever you named your placeholder image. Replace the assignment with whatever contains your image path. You should be able to add as many of these as you want.
SOURCE:
http://www.databasedev.co.uk/bound_image_report.html

Related

Replace a Picture in MS Word header with another in VBA

Using MS access I need to open a word document and change certain images within the header. Whilst I have the code to find and replace any text that I need, I do not quite understand how to replace an image keeping it to a specific width and height.
The header within the Word document is constructed using a basic table with 3 columns as depicted below. The image in the right hand column will need to change for a specific logo.
I have managed so far to add an image to the document using the following code which gives the expected result...
With WordDoc.StoryRanges(wdPrimaryHeaderStory)
.InlineShapes.AddPicture FileName:="test.jpg"
End With
I understand that this is due to me not specifying a specific location, size etc but I am struggling to find resources which would instead allow me to either remove and add a new image to the right column or just swap the images out.
EDIT 1:

Store image in Word document to insert later

I am currently building a word-template for a report. In this report are used red separators as part of the design. The separators are basically just images of red, curved lines.
Instead of copy and pasting these separators when needing them, is there a way to store the image somewhere in the document, allowing it to be inserted with just the click of a button in the ribbon? My first bet would be to create a macro somehow that would insert the image, however that would require the image to be stored in a very specific path on the computer.
As this document is gonna be used by lots of people without this image stored on their harddrive, i need another way.
Thanks so much in advance!
You could insert the images into bookmarks created via SET fields in, say, the document header, then reproduce them elsewhere in the document via cross-references. The images in the SET fields wouldn't themselves be visible.
For example:
{SET Image1 "Actual image1"}
to create the bookmark and
{REF Image1}
to display the image.
No code required.
By default, the size of the pictures when inserted via a cross-reference will be the same size as they are in the SET field, plus they'll be formatted as in-line with text.
If they're meant to be full-width images, simply make sure to insert the cross-reference into a new paragraph with 0 indenting.
To constrain the images' displayed size to something smaller than the width they're inserted into the SET field at, insert them into a table whose row height and/or column width has the required fixed dimension.
To apply text-wrapping, insert the cross-references into a table and format the table's wrapping as 'around'.
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message.

Can I use the Shrink Method for the whole document in word

I don't know anything about code. I work with e-learnings in Storyline 3. I sometimes localize these e-learnings and use the translation tool in Articulate which basically exports an MS Word file. Sometimes the target languages are longer and I need to decrease the font size by percentage for the whole document. Usually, there are at least 3 different font sizes that I need to decrease accordingly. I am wan to develop a macro that I will use for multiple documents.
I couldn't find a way to do this by percentage, but looks like the Shrink or Grow Methods will do the work! I found this code in the reference page but looks like it works only for a selected object. The issue is that the exported MS Word file is in a table with each text box in the storyline separated to a cell. When I select the whole table it does not work.
If Selection.Type = wdSelectionNormal Then
Selection.Font.Grow
Else
MsgBox "You need to select some text."
End If
Could you please help me and let me know if this would be possible for the whole document, or the selected table? It would be very much appreciated. Thanks in advance.
It is unclear from your question whether the table in the Word document contains the actual text boxes or just the text they contain.
If it is just the text then Shrink may work. I tested this on a document with a single table containing only text:
ActiveDocument.Range.Font.Shrink

How do I differentiate between placeholders (Tags, Id, Name) on a template and have the label stay once the template is used in the presentation

I am creating a custom slide template with 8 picture placeholders and 4 text placeholders. The idea is that the user would "fill-in" the template with the text and images and once a macro is run, the values of the placeholders would be collected and added to a JSON file. Ideally, two picture placeholders (big_screen_i and small_screen_i) and one text placeholder (caption_i) would be collected as one JSON object. This set would be repeated 4 times on the same slide.
Here are my problems:
1) The name of the placeholder set in the slide master view changes when more than one of the same template is used (haven't pinpointed the exact trigger). The names also change once an image is inserted into the placeholder. Locating an object by name becomes unstable.
2) Using the .type of placeholder (picture vs text) doesn't differentiate between the big_screen_i and small_screen_i.
3) Tags and keys also change or disappear when using the template more than once (because of the repeated name).
4) I am unable to group the objects because its not possible to group placeholders.
Is there a way to identify each shape/placeholder and connect it to the added content?
Note: I am using powerpoint 2016 .potm file
Thank You!

Insert image from URL bookmark Microsoft word

I have a image URL contained in my sql database.
I create a bookmark for that column in the word document (this works fine).
Now I want to use the image URL that is passed from the database to insert an image.
I have tried hyperlink (does not work and does not display image).
I have tried Quick Parts - IncludePicture (does not work).
I have been Googleing and have not found anything that works.
Ok let me simplify this.
I want to insert a image using an URL.
You can do this in alot of different ways I know.
For instance using Quick Parts and the selecting IncludePicture you would the past the URL of the picture and BAM image inserted.
Now I want to do exactly that with one exception. The URL is a microsoft word bookmark that I get from my database.
For some reason this does not want to work. I have also checked the bookmark data and it is correct and yes it is a valid URL because if I copy and paste it from the database in the way I described above it works.
So is there any other way to do this?
To be honest I still don't know where is exactly your problem. I assumed that you have knowledge and code to take both bookmark name and url from your database using VBA. If so, there would be quite simple code which would allow you to load picture from web to bookmark in your word document.
Below is the code I have tested with half of success. If I add any picture it will work fine. But will not work with url of active google map. I have no idea what you you mean with 'static google map' (in comment), you didn't provide any example therefore you need to make your own test.
Before you run this for test be sure you have two bookmarks in your active document: bookmark_logo and bookmark_poland. Hope this will help a bit.
Sub Insert_picture_To_Bookmark()
Dim mapURL As String
Dim soLOGO As String
soLOGO = "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png"
ActiveDocument.Bookmarks("bookmark_logo"). _
Range.InlineShapes.AddPicture _
soLOGO, True, True
mapURL = "https://maps.google.pl/maps?q=poland&hl=pl&sll=50.046766,20.004863&sspn=0.22047,0.617294&t=h&hnear=Polska&z=6"
ActiveDocument.Bookmarks("bookmark_poland"). _
Range.InlineShapes.AddPicture _
mapURL, True, True
End Sub