u/Pl4sic

▲ 5 r/vba

Excel VBA replace a bookmark in a word document with a picture

I would like to replace a bookmark inside a word document with a picture.

I have:


Sub makro()


Dim wApp As Object
Dim wDoc As Object
Dim bR As Object
Dim b1 As String
Dim b2 As String
Dim fp As String
Dim stuff As String

b1 = "Bookmark 1"
b2 = "Bookmark 2"
fp = "my file path"
stuff = "some text"

Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Open(fp)

Set bR = wDoc.Bookmarks(b1).Range
bR.text = stuff        'this is how I do it with text

Set bR = wDoc.Bookmarks(b2).Range
'???

'I know of wDoc.Content.InlineShapes.Addpicture FileName:=filepath etc. but not how to apply it at the position of the bookmark.

Set wApp = Nothing
Set wDoc = Nothing
Set bR = Nothing

End Sub

Is there a simple way of replacing b2 with a picture, like I did with b1?

I might have missed some necessities in the code. Like closing/quitting the word document and application, but that is irrelevant to the question and I can figure that out on my own.

I would appreciate any ideas and suggestions.

I use Office 365.

reddit.com
u/Pl4sic — 14 days ago
▲ 4 r/excel

Find several matches for a single search criteria out of a matrix and output the corresponding value out of a column

Here is the situation:

​

Let's say we have a column for products, 3 rows:

a12

a13

a14

​

And we have a matrix for suppliers, 3 rows, 3 columns:

a | b | c

d | a | e

b | f | a

​

The column and matrix share the same rows.

​

For each supplier I would like to list every product they can deliver, so the result here should be:

a | a12 | a13 | a14

b | a12 | a14

c | a12

d | a13

e | a13

f | a14

​

I would have the list with suppliers (a...f), then their positions should be found in the matrix and the associated articles should be output, as preferably an array, out of the column.

​

For example:

We have supplier b, they appear in r1 c2, and r3 c1.

The products a12 and a14 are in r1 and r3, so they should be listed.

Since the suppliers should be listed vertically, it would be nice to have the output horizontally as an array.

​

I have tried a few functions, but they were coming short for one reason or another. Although, it could also be my lack of experience. I played around with the xlookup, filter, match functions for instance. Also, everything is obviously simplified, it could be a list with 3 or 300 products, and likewise varying amounts of suppliers.

​

I would appreciate all suggestions and or ideas.

Office 365 is what I use.

reddit.com
u/Pl4sic — 21 days ago