2 Attachment(s)
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.
Attachment 168485
When they click Replace Styles, I'm getting this
Attachment 168483
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.
Re: No Such Interface Supported
Quote:
I've imported the dotx into the document with
can you then use the imported styles if you change the style manually?
Re: No Such Interface Supported
Quote:
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.
Re: No Such Interface Supported
does styletosetto contain a valid style object?
1 Attachment(s)
Re: No Such Interface Supported
Quote:
Originally Posted by
westconn1
does styletosetto contain a valid style object?
Attachment 168589
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}