如何将此VB代码转换为C#? [英] How do I convert this VB code to C# ?

查看:107
本文介绍了如何将此VB代码转换为C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将此VB代码转换为C#?这是VBA代码。



我尝试过:



< pre lang =vb> 如果 cmbhlevels.Value = 1 然后
ActiveDocument.AttachedTemplate.AutoTextEntries( z_TOC1)。插入位置_
:= Selection.Range,RichText:= True
结束 如果





如何将此代码重写为c#?请帮帮我...

解决方案

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





看起来原始代码是VBA,因此它不太可能在独立的c#项目中按原样运行因为没有ActiveDocument等概念。


你可以使用在线代码转换器



https://www.carlosag.net/tools/codetranslator/


选项A

第0步;学习C#

MSDN _ Visual C#和Visual Basic入门 [ ^ ]

步骤1;查看文档

Document.AttachedTemplate属性(Microsoft.Office.Tools.Word) [ ^ ]

选项B

步骤0;雇用开发人员


How do I convert this VB code to C# ? Here is VBA Code.

What I have tried:

 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...

解决方案

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.


You can use online code converter

like https://www.carlosag.net/tools/codetranslator/


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


这篇关于如何将此VB代码转换为C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆