Results 1 to 7 of 7

Thread: [RESOLVED] Word Template Not Found

  1. #1

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,735

    Resolved [RESOLVED] Word Template Not Found

    I'm writing my first ever VSTO application, and running into a bit of an oddity. I am trying to create a document based on a template like so:

    Code:
    Dim newDoc = Globals.ThisAddIn.Application.Documents.Add(Template:="C:\Users\etc\SCPTemplate1.dotx")
    I altered the path slightly, to hide some information, but that shouldn't matter. This throws a file not found exception, and the details state that the file in question couldn't be found.

    I checked the path, and that is correct, so I then added a check using IO.File.Exists() to see whether or not the file was there. This returned True, so the file is there, and the path is completely correct.

    Furthermore, while the exception pops up, the program continues past that point. A file does exist, and it even pretty much looks like the template (I'm not quite certain of that, as I may have been looking at the wrong thing, and a second issue occurs right after that which is unrelated to this problem).

    So, what is this exception about? Why am I getting it when I can verify that the path is correct and the file visible? And also, why does the fact of the exception not seem to have any impact on the behavior of the addin?
    My usual boring signature: Nothing

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    729

    Re: Word Template Not Found

    have a look here : https://social.msdn.microsoft.com/Forums/office/en-US/c70f4811-66a1-4c6e-848c-a079b2b89402/vbnet-using-a-word-templte-to-create-a-document?forum=worddev


    and here : https://stackoverflow.com/questions/...-word-document


    it seems that the guys managed to create their file without error. But don't forget to force the new document to save as a .docx else you will save the .dotx
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,735

    Re: Word Template Not Found

    Darn, that answer makes it worse, if anything. The first didn't have any issue, the second is closer to what I was doing, and they report essentially the same error....but there isn't really a solution, unless the error they were getting came from setting the style, not from the template, and that issue doesn't apply to my situation. They suggest that changing away from .Style solved the problem, which would mean that the line where they created the document was NOT causing a problem, but it sure is for me.
    My usual boring signature: Nothing

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,469

    Re: Word Template Not Found

    I altered the path slightly,
    the path shown in the above should not cause an issue, but some other paths may do so if affected by virtualization
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,735

    Re: Word Template Not Found

    The alteration on the path was only changing the name of the folder, so it's a faithful representation of the what the actual folder is. Still, I think I'll try moving the template somewhere more...accessible.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,735

    Re: Word Template Not Found

    The message that I'm getting is that it wasn't able to find this template:

    file:///C:/Users/etc/Documents/SCPStuff/SCPTemplate1.vsto

    I thought that this might have to do with trusted locations, so I added that folder to the trusted locations. That had no real impact. The code I am using comes directly from an MS document:

    https://docs.microsoft.com/en-us/vis...s?view=vs-2019

    And, aside from the fact that I get an error message each time...it is actually working. I had some other issues to work through when I originally posted this, but those have been worked through.

    A further observation is that this doesn't appear to be a typical error message, though I don't have enough experience with automating Word to know. The error message has a title of "Microsoft Office Customization Manager", and it follows with Installing Customization (in bold), then on the next line, "There was an error during installation."

    This set of facts suggests to me that I'm not really running into an error in my VSTO plugin, but an error in that Customization Manager, which I don't even know what that is. So, I'm off to see what I can find on that one.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,735

    Re: Word Template Not Found

    And then I noticed the file extension....

    So, it wasn't the template it couldn't find, which would be .dotx, it wasn't able to find the .vsto file, because that file wasn't there.

    Frankly, I was going back and forth as to whether or not I should even use a template for this, and it is rather looking like the template is more trouble than it's worth. It doesn't gain me a whole lot, though I thought it might be ever so slightly easier to work with. However, while looking around at this error message, it began to look like I'll just keep running into issues if I try the template approach that I was using (which wasn't just a normal template, but a VSTO template).

    So, I think this one can be said to be solved.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width