Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a document with bookmarks location for specific photo and I need to refresh the photos monthly word doc, wonder if there is a VBA to help me with it?

The file name of the photo will be consistent.

e.g bookmark 1 = cat 1
bookmark 2 = cat 2

What I have tried:

I am reading "https://software-solutions-online.com/word-vba-insert-images/" and the section insert image at specific location. that bookmark example is what i wish for. but i do not know how to apply and write into a code:) send help pls, thank you!

Hi Richard thanks for helping, I run the code but it stated not a valid file name. wonder what is the problem
VB
Sub Example2()
'move the cursor to the bookmark
Selection.GoTo What:=wdGoToBookmark, Name:="Bm1"
'insert the image
Selection.InlineShapes.AddPicture FileName:= _
    "C:\Users\MYNAME\OneDrive - MYNAME\Desktop\SC File", LinkToFile:=False, _
    SaveWithDocument:=True
End Sub
the image is inside my onedrive file name SC file
Posted
Updated 30-Aug-22 21:25pm
v2
Comments
CHill60 31-Aug-22 3:27am    
Is it called "SC File" or "SC File.jpg"?
Richard MacCutchan 31-Aug-22 3:42am    
It is a simple matter to copy the exact name of your file. Although it would be better not to hard code it in your application, but pass it in as a parameter.

Hi Richard thanks for helping, I run the code but it stated not a valid file name. wonder what is the problem

Sub Example2()
'move the cursor to the bookmark
Selection.GoTo What:=wdGoToBookmark, Name:="Bm1"
'insert the image
Selection.InlineShapes.AddPicture FileName:= _
    "C:\Users\MYNAME\OneDrive - MYNAME\Desktop\SC File", LinkToFile:=False, _
    SaveWithDocument:=True
End Sub



the image is inside my onedrive file name SC file
 
Share this answer
 
Comments
CHill60 31-Aug-22 3:24am    
This is not a solution. If you want to respond to a post then use the "Have a Question or Comment?" next to it. You should also put this code into your question. I am going to do that for you before this solution disappears (3 reports and it will be deleted)
The link you posted has a section that explains how to use a bookmark to position the image.
 
Share this answer
 
Comments
CHill60 31-Aug-22 3:25am    
OP has tried to respond with a "solution" - I've moved his code into his post

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900