How to use a File Path with a space character with Office automation


I use a build step (Copy File) to add an image file to the ressource folder to make sure it is always available to the the web app.

When I try to add it to the word document I get an OLE Exception “Invalid file name”.

The fact that the generated resource folder name has a “space” before “Resources” causes the error.

I know that I could add the file to the app folder but I would prefer put it at the same place as the other files.

Is there a way to solve that?


Have you tried to use SpecialFolder.Resources?
It should work without any problem with spaces in the pathname.

If you are using the pathname you can try to add quotes, Chr(34), at the beginning and the end of the pathname.

Chr(34) + <pathname> + Chr(34)


Well kind of… I’ve tried "SpecialFolder.GetResource(filename)" but it doesn’t work.

I finally tried a path in the app directoty that hasn’t any spqce in it and it doesn,t work either. So, you are right, that is not the problem. It was a bad assumption from my part.

It might have something to do with the access too the folder.

I will find another way to make sure the file is always in place…


It should be

Dim imgFile f As FolderItem imgFile = SpecialFolder.Resources.Child(filename)

I have tried to surround the path with quotation marks, and it works in some situations.

””””C:\\my path with spaces\\myname.exe””””

@Eugene Dakin
That’s the same as what I was saying by using Chr(34).
I find all those quotes always very confusing. :wink:

Hi Paul,

Yes, you are right that your solution is much cleaner. I should know better than to answer while reading conversations on my phone. :slight_smile:


I’ve tried this


and this

 tableauDetailed.Cell(5, 1).Range.InlineShapes.AddPicture( "C:\\Apache24\\htdocs\\windhub_DEMO\\webservice\\Windhub_WebReporter\\DebugWindhub3_0_WebReporter\\DebugWindhub3_0_WebReporter Resources\oPhoto.jpg", False, True) 

without success.

The path name doesn’t exceed the maximum length of 259 characters; it has only 140. The folder is readable and writable (at least that’s what the folderitem properties are showing.

Creating a macro in word to add the picture works.

Sub Macro1() ' ' Macro1 Macro ' ' Selection.InlineShapes.AddPicture FileName:= _ "C:\\Apache24\\htdocs\\windhub_DEMO\\webservice\\Windhub_WebReporter\\Windhub3_0_WebReporter Resources\oPhoto.jpg" _ , LinkToFile:=False, SaveWithDocument:=True End Sub

I don’t understand what is going on…

Any clue?

Finally identified the problem… behind the keyboard… The Build step that had to load the file into the ressource directory was not able to find the file in the test environement.