Hello MVP's,
I believe this to be quite easy, however, I just don't know the right syntax for it.
My question is about the following line: Rng.Text = vbNullString '<-- This only deletes text, not images
Sometimes I want to replace an existing client image, however, the code posts an additional image everytime, while it should delete the existing one.
Perhaps I haven't inserted the image into the bookmark, but instead after it.
I have tried the following, which didn't work: Set Rng = ActiveDocument.Bookmarks("Client_logo").Range.InsertBefore
Thank you for looking into my problem.
Kind regards,
Rolf
I believe this to be quite easy, however, I just don't know the right syntax for it.
My question is about the following line: Rng.Text = vbNullString '<-- This only deletes text, not images
Sometimes I want to replace an existing client image, however, the code posts an additional image everytime, while it should delete the existing one.
Perhaps I haven't inserted the image into the bookmark, but instead after it.
I have tried the following, which didn't work: Set Rng = ActiveDocument.Bookmarks("Client_logo").Range.InsertBefore
Code:
Sub AutoLogo()
[COLOR=#008000]
''''''''''''''''''''''''''''''''''''''''''''''''''''
'Populate textbox: txtLogo
''''''''''''''''''''''''''''''''''''''''''''''''''''[/COLOR]
[COLOR=#008000]'Establish connection[/COLOR]
Set dbs = OpenDatabase("C:\Users\Public\Downloads\Contacts.accdb")
[COLOR=#008000]'Fill recordset with data matching the text of combo cboContacts[/COLOR]
Set rst = dbs.OpenRecordset("Select * FROM Projects WHERE Projects.Project_Number & ' ' & Projects.Project_Title = '" & Me.cboContacts.Text & "';")
[COLOR=#008000]'Fill Textbox with Hyperlink from Databasa[/COLOR]
txtLogo.Value = ("" & rst.Fields("Hyperlink"))
[COLOR=#008000]''''''''''''''''''''''''''''''''''''''''''''''''''''
'Fill 'Client_logo' bookmark in document header
''''''''''''''''''''''''''''''''''''''''''''''''''''[/COLOR]
Dim ClientLogo As InlineShape
Dim Rng As Range
[COLOR=#008000]'Identify current Bookmark range and insert image[/COLOR]
Set strBM = txtLogo
With ActiveDocument
Set Rng = ActiveDocument.Bookmarks("Client_logo").Range
Rng.Text = vbNullString [COLOR=#b22222]'<-- [B]This only deletes text, not images[/B][/COLOR]
Set ClientLogo = .InlineShapes.AddPicture(FileName:=strBM, LinkToFile:=False, Range:=Rng)
With ClientLogo
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(3.5)
.Height = CentimetersToPoints(1.25)
End With
[COLOR=#008000]'Re-insert the bookmark[/COLOR]
.Bookmarks.Add "Client_logo", Rng
End With
End Sub
Thank you for looking into my problem.
Kind regards,
Rolf