PDA

View Full Version : Replacing text with a image



Robert87
12-19-2013, 02:28 AM
Hello!

I´m using this vba code to change font on certain letters in certain cells.


Option Explicit
Option Compare Binary

Sub WingDingsFtoM1()
Dim c As Range, r As Range
Dim v As Variant, a() As String, i As Integer

Set r = Range("F3,AA3,F15,AA15,F27,AA27,F39,AA39,F51,AA51,F63,AA63,F75,AA75,F87,AA87,F99,A A99,F111,AA111,F123,AA123,F135,AA135,F147,AA147,F159,AA159,F171,A171,F183,A A183,F195,AA195,F207,AA207,F219,AA219,F231,AA231,F243,AA243,F255,AA255,F267 ,AA267,F279,AA279,F291,AA291")
a() = Split("f g h i j k l m", " ")

For Each c In r
With c
If IsEmpty(c) Then GoTo NextC
For i = 1 To Len(.Value2)
For Each v In a()
If .Characters(i, Len(.Value2)).Font.Name <> "Wingdings 3" And _
Mid(.Value2, i, 1) = v Then _
.Characters(i, 1).Font.Name = "Wingdings 3"
Next v
Next i
NextC:
End With
Next c
End Sub





Now I need to add a function to that script.

I need it to replace the word "streck" with an image of my choice, in the same cells.

Could anyone help me with this?

Aflatoon
12-19-2013, 03:08 AM
I don't follow - you can't put an image in text. Or did you mean a symbol?

Robert87
12-19-2013, 04:24 AM
I want to remove the word streck, and put a image in the same place as the text was. If that´s possible.

Aflatoon
12-19-2013, 04:42 AM
As I said, you cannot put an image within a cell's text.

Kenneth Hobs
12-19-2013, 07:56 AM
I normally do not view posts where Aflatoon has responded as he is usually right on target.

When posting code, please use code tags, not quote tags. Use the Go Advanced button to get the advanced editor if not set as the default. It shows a toolbar with the # icon that inserts the code tags. It is located right next to the quote icon for quotes. Quotes are seldom needed though. Those are good for non-code text alignment or snippets of someone's posted text. It is best to use it sparingly.

Another option for you, now that you have 5 posts, would have been to simply post the link to the thread where the code resides. http://www.vbaexpress.com/forum/showthread.php?48445-Changing-font-on-certain-letters

You did good starting another thread.

Regarding this question, I am not sure how the other post relates. If you are just looking for a word in a cell to overlay a picture image object, that is certainly doable. I forget which, length or width, dimension of a cell is a problem getting for resizing the picture image to position to the top left of a cell.

Please provide more details of just what image you want to position or insert. Some like to insert the image from a file and some like to use an image object already in the workbook. If your goal is overlay the cell with contents of the cell as a picture image object, that can be much more involved.

These things can be a bit involved so don't expect many responses or fast responses. It just depends on the details of the need.

If more than one file is needed, zip and attach it to help us help you more readily. e.g. Zip a workbook with before and after sheets and 1-2 JPG files that were inserted in the after sheet short example.