-
May 17th, 2019, 04:57 AM
#1
Thread Starter
Member
No Such Interface Supported
Hi, I am trying to replace styles in a document (doc or docx) with styles from a template document (dotx). I've imported the dotx into the document with
Code:
Globals.ThisAddIn.Application.ActiveDocument.CopyStylesFromTemplate(Template:=DirectoryForRestyler & cbxNewStyleSheets.SelectedItem.ToString & ".dotm")
so that all the styles needed exist in the document. I then have a CustomTaskPane where the user selects the old style from the document by range, and replaces it with a new style.
When they click Replace Styles, I'm getting this
Code:
No such interface supported
No such interface supported
at Microsoft.Office.Interop.Word.Range.set_Style(Object& prop)
at <application>.Button1_Click(Object sender, EventArgs e) in <redacted>.vb:line 77
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
It's got me at a complete roadblock and I don't know how to progress. Looking at the microsoft docs, it states I should be able to set the style, so I'm not sure where I am going wrong.
https://docs.microsoft.com/en-us/off...rd.range.style
If you need any more details, I can provide them. Help would be appreciated. Thanks.
Last edited by TheMeq; May 17th, 2019 at 05:34 AM.
~ TheMeq ~
If I helped in anyway, please hit the star and send me some rep! Thanks
-
May 17th, 2019, 06:21 AM
#2
Re: No Such Interface Supported
I've imported the dotx into the document with
can you then use the imported styles if you change the style manually?
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
-
May 17th, 2019, 06:49 AM
#3
Thread Starter
Member
Re: No Such Interface Supported
Originally Posted by westconn1
can you then use the imported styles if you change the style manually?
Yes, I am able to use the styles manually by selecting them from Home > Styles.
~ TheMeq ~
If I helped in anyway, please hit the star and send me some rep! Thanks
-
May 17th, 2019, 07:11 AM
#4
Re: No Such Interface Supported
does styletosetto contain a valid style object?
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
-
May 20th, 2019, 05:15 AM
#5
Thread Starter
Member
Re: No Such Interface Supported
Originally Posted by westconn1
does styletosetto contain a valid style object?
This is what I have, I noticed that the type is different but not sure how to get around this.
+ par.Range.Style {System.__ComObject} Object {System.__ComObject}
+ styleToSetTo {System.__ComObject} Microsoft.Office.Interop.Word.Style {System.__ComObject}
~ TheMeq ~
If I helped in anyway, please hit the star and send me some rep! Thanks
Tags for this Thread
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
|