Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I convert this VB code to C# ? Here is VBA Code.

What I have tried:

VB
 If cmbhlevels.Value = "1" Then
ActiveDocument.AttachedTemplate.AutoTextEntries("z_TOC1").Insert Where _
:=Selection.Range, RichText:=True
End If


How can I rewrite this code to c# ? Please help me...
Posted
Updated 10-Jul-17 23:44pm

if (cmbhlevels.Value == "1")
{
    ActiveDocument.AttachedTemplate.AutoTextEntries("z_TOC1").Insert (Where: Selection.Range, RichText: true);
}


It looks like the original code is VBA though so it's unlikely to work as-is in an independent c# project as there is no concept of "ActiveDocument" etc.
 
Share this answer
 
Comments
Member 12955507 11-Jul-17 7:24am    
Microsoft.Office.Interop.Word.Document doc1 = Globals.ThisAddIn.Application.ActiveDocument;

This is the active document

I am using

doc1.AttachedTemplate.AutoTextEntries("z_TOC1").Insert (Where: Selection.Range, RichText: true);

But we dont have property name as AttachedTemplate
You can use online code converter

like https://www.carlosag.net/tools/codetranslator/
 
Share this answer
 
Option A
Step 0; Learn C#
MSDN _ Getting Started with Visual C# and Visual Basic[^]
Step 1; Review the documentation
Document.AttachedTemplate Property (Microsoft.Office.Tools.Word)[^]
Option B
Step 0; Hire a developer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900