-
Oct 14th, 2021, 04:50 PM
#1
[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
-
Oct 14th, 2021, 06:00 PM
#2
Re: Word Template Not Found
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)
-
Oct 15th, 2021, 01:54 PM
#3
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
-
Oct 16th, 2021, 06:06 AM
#4
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
-
Oct 16th, 2021, 12:39 PM
#5
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
-
Oct 19th, 2021, 04:10 PM
#6
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
-
Oct 19th, 2021, 04:25 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|