1

I link an image into a word document using this snippet:

.InlineShapes.AddPicture("c:\absPath\to\myImage.jpg")

but I am not able to use relative paths

.InlineShapes.AddPicture(".\relPath\to\myImage.jpg")

MS-word returns an error or replaces it with absolute path (depending on MS-word version).

But for me having a relative path to external file is important, in my case I want to check-in the word document and the images into SVN and when this is check-out in a different location, the absolute path doesn't work anymore.

Any ideas or solutions?

Domenico
  • 43
  • 6
  • Make your path absolute by concat `wDoc.Path & "\rel\path\to\image.jpg"`. – BitAccesser Sep 09 '17 at 05:45
  • Understood, this solution does only work at the moment I generate the document. But when you open the word document you still have absolute paths there. – Domenico Sep 09 '17 at 07:00
  • You want the pic to change in different locations? Then delete and add again [using-vba-to-change-picture](https://stackoverflow.com/questions/10169011/using-vba-to-change-picture) is an option? If not give more info what you want to archive. – BitAccesser Sep 09 '17 at 08:03
  • I want that the image is always expected at the same relative path to the word document without necessity to run VBA. I.e. that the relative path information should finally be located in the word document. – Domenico Sep 09 '17 at 12:16
  • After adding the image is stored in the word doc, so why do you need a relative path? – BitAccesser Sep 09 '17 at 12:22
  • The images are linked not stored ... and I want to be able to replace the images being independant of absolute location of the images ... just to care of relative folder paths ... e.g. word document and images are in SVN allowing colleagues to check out without caring of absolute paths – Domenico Sep 09 '17 at 16:06
  • Edit your question and put all relevant information (including a brief description of desired workflow) there! Maybe [this](http://windowssecrets.com/forums/showthread.php/154379-Word-Fields-and-Relative-Paths-to-External-Files) helps? – BitAccesser Sep 09 '17 at 16:34
  • @BitAccesser - You are absolutely right, I didn't describe my problem correctly, but finally you understood me and you were able to point me to the solution. It seems that MS-word works with absolute paths only and that you can use relative paths only using tricks - How can I set it to "accepted answer"? – Domenico Sep 09 '17 at 18:15
  • Feel free to post an answer yourself, with your solution (my last link?). Don't forget to update your question (use of SVN, why to link and not to store the pics, add the link parameter to addPicture (that has confused me, cause without the pic get saved in doc, etc.). Then others can benefit from our research. – BitAccesser Sep 09 '17 at 18:24

1 Answers1

0

"BitAccesser" in one of his comments pointed to this solution.

It seems that MS-word works with absolute paths only and that you can use relative paths only using tricks.

The trick given in the link above takes some time to understand and implement but does the job.

Domenico
  • 43
  • 6
  • You should add this [github link](https://github.com/filosofianakatemia/imq) to the code as http://windowssecrets.com needs registration for download. If you get more detailed in question and answer (e.g.: relevant code parts), I will vote for both! Don't forget to accept your answer (you have to wait some time). – BitAccesser Sep 09 '17 at 18:57
  • @BitAccesser - I was able to understand the solution by the link only, github link was not necessary. I don't bother for "votes" as you don't bother for "accepted answers". I would only enhance question and answer if you feel that this would help future readers – Domenico Sep 09 '17 at 19:02
  • To help future readers is essential as many people have the same questions (otherwise, we could delete this question). If you have a look at my profile, you see 0 questions. But not because I know everything, it's because I benefit from solutions provided by others. You should take my votes to gain enough reputation, to comment on questions and answers not made by you (you need 50), what is annoying if you can't. – BitAccesser Sep 09 '17 at 19:10