Trying to insert image into Word Table using VBA - vba

Im trying to use an input table and output table, where the inputs autofill the output using IF functions. For one of the Outputs, i need to the information in the cell to be in a table format. I thought inserting an image would be easier than embedding a table, so i tried that. Cant get it to function tho.
I have tried the following:
If input6 = "putimagehere" Then
Dim img As String
img = "Image path"
table2.Cell(18, 3).Select
Selection.InlineShapes.AddPicture img
End If
It recognises the tables, all other putputs are correct, just the one that requires the image.
Any thoughts?

Related

Insert Pictures by file path in document for hundreds of pages that match common name MS Access 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

VBA equivalent to Save As Picture in PPT

I am trying to use vba to save grouped shapes as an image in powerpoint. The "save as picture" function that you can use by right clicking on the group produces high quality images. My attempt to recreate the right-click function produces blurry, low quality images. Is there a way to exactly recreate the right click save as picture instead of export?
ActivePresentation.Slides(1).Select
Call ActiveWindow.Selection.ShapeRange(1).Export( _
"C:\myloction.png", _
ppShapeFormatPNG)
Add optional scaleheight/scalewidth parameters after the ppShapeFormat parameter. The results seem almost random, I don't know exactly what the parms are supposed to relate to, but the bigger the number you feed it, the higher the rez of the exported image.

Add a URL image to a cell where the URL is based on input in another cell

I am moving over a worksheet from GoogleDocs that has to be in Excel now.
It is a barcode generator sheet.
The image cell in GoogleDocs has the formula is
=image("www.somebarcodesite.com/image.php?code=" & A2 & "&style=197&type=C128B&width=300&height=50&xres=1&font=3", 3)
I've downloaded as Excel but that has not helped (I think due to text concatenation) and additional rows may be need to be added so it's not enough to embed the image once when downloading.
I've seen VB solutions to put an image in a cell, but I'm not sure it would allow the users to add new rows to the worksheet.
Does anyone know where I should start on finding a scalable way to show the image generated at a url, where the url is generated dynamically based on the input of other cells?

How to choose a different header image in MS Word 2013 using a macro/button

I'd like to create a Word stationary template with ability to cycle through different colored logos in its header. My company uses a logo in five different colors and I would like to create a single template with a button that would allow me to cycle through the different colored logos every time I create a new document from this template. Can this be done, perhaps with a little VBA?
Edit:
After working with an answer from Olle Sjögren I've come up with the following working script:
Option Explicit
Public imgCounter As Integer
Sub cycle_logos()
Dim I As Variant
Dim logoColors(4) As String
logoColors(0) = "logo_magenta.png"
logoColors(1) = "logo_teal.png"
logoColors(2) = "logo_orange.png"
logoColors(3) = "logo_red.png"
logoColors(4) = "logo_grayscale.png"
For Each I In logoColors
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).ShapeRange.Item(I).Visible = msoFalse
Next I
imgCounter = imgCounter + 1
If imgCounter = 5 Then imgCounter = 0
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).ShapeRange.Item(logoColors(imgCounter)).Visible = msoTrue
End Sub
It is worth mentioning how I came up with the image names, since I didn't find a way to do this from inside Word. I renamed the template extension to zip and unzipped it. In the extracted files I opened word\header2.xml (this may vary, depending on the position in the document) and edited the nodes containing the names of pictures, i.e. <wp:docPr/>, e.g.:
<wp:docPr name="Picture 1" id="1"/>
became:
<wp:docPr name="logo_magenta.png" id="1"/>
etc. I then replaced the XML file in the ZIP with my edited version and changed the extension back to dotm.
As mentioned, there are several ways to do this. I would suggest storing the images outside of the template, otherwise all documents based on the templates would include all logo images, even if they are not shown, making the documents bigger than they need to be. That approach makes installing the template a bit harder, since you would have to copy the images to the clients as well as the template file.
To answer your question regarding addressing the images in the header - you can address then through the correct story range object. In my example I assume that they are in the primary header. To tell the different images apart, you can use the Name property or the index in the Item collection:
ThisDocument.StoryRanges(wdPrimaryHeaderStory).ShapeRange.Item("Picture 1").Visible = msoTrue
ThisDocument.StoryRanges(wdPrimaryHeaderStory).ShapeRange.Item(1).Visible = msoFalse

VBA deletes image in body instead of header in MS-Word

I have MS Word files that have a header with 2 Text Boxes and one image (as logo) and some tables, texts and images in body.
I'm trying to remove the image in header (logo) with this VBA code:
Dim tmp As Shape
Dim dShape As Shape
For Each tmp In ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes
If tmp.Type = msoPicture Then
Set dShape = tmp
End If
Next
dShape.Delete
In the first test it worked correctly! After that it removes body image instead of header image!!!
It seems we should first select the Shape we want to delete!!
I don't know why when I say shape1.Delete it thinks : let me see, mmmm... I think i is better to do shape2.Delete , so i'll do that.
any way this works:
dShape.Select
dShape.Delete
VBA is a fool (Just like its platform)!