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

  1. 5 weeks ago

    Roger S

    Jan 11 Gaspé, Québec, Canada
    Edited 5 weeks ago

    Hi,

    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?

    Thanks!

    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.

    Sorry...

  2. Paul S

    Jan 11 Pre-Release Testers, Xojo Pro Europe (Netherlands, Den Haag)

    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)
  3. Roger S

    Jan 11 Gaspé, Québec, Canada
    Edited 5 weeks ago

    HI,

    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...

    Thanks!

  4. Paul S

    Jan 11 Pre-Release Testers, Xojo Pro Europe (Netherlands, Den Haag)

    It should be

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

    Jan 11 Pre-Release Testers, Xojo Pro Canada scispec.ca

    I have tried to surround the path with quotation marks, and it works in some situations.
    ””””C:\my path with spaces\myname.exe””””

  6. Paul S

    Jan 11 Pre-Release Testers, Xojo Pro Europe (Netherlands, Den Haag)

    @Eugene D
    That's the same as what I was saying by using Chr(34).
    I find all those quotes always very confusing. ;)

  7. Eugene D

    Jan 11 Pre-Release Testers, Xojo Pro Canada scispec.ca

    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. :)

  8. 4 weeks ago

    Roger S

    Jan 16 Gaspé, Québec, Canada

    Hi,

    I've tried this

     SpecialFolder.Resources.Child(nomPhoto).NativePath

    and this

     tableauDetailed.Cell(5, 1).Range.InlineShapes.AddPicture( "C:\Apache24\htdocs\windhub_DEMO\webservice\Windhub_WebReporter\DebugWindhub3_0_WebReporter\DebugWindhub3_0_WebReporter Resources\NoPhoto.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\NoPhoto.jpg" _
            , LinkToFile:=False, SaveWithDocument:=True
    End Sub


    I don't understand what is going on...

    Any clue?

  9. Roger S

    Jan 16 Answer Gaspé, Québec, Canada

    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.

    Sorry...

or Sign Up to reply!