将 VB.NET 代码转换为 VBScript
我有一段 VB.NET 代码,我想将其转换为 VBScript。 它基本上启动 Microsoft Word,显示“打开”对话框,并通过邮件合并所选文档。 任何帮助将不胜感激。
Dim oMissing As Object = System.Reflection.Missing.Value
Dim oEndOfDoc As Object = "\\endofdoc"
Dim oFalse As Object = False
'Start Word and create a new document.
Dim oWord As Word._Application
Dim oDoc As Word._Document
oWord = New Word.Application()
oWord.Visible = True
'show box
Dim dlg As Word.Dialog = oWord.Dialogs(Word.WdWordDialog.wdDialogFileOpen)
Dim dlgType As System.Type = GetType(Word.Dialog)
' Set the Name property of the dialog box.
dlgType.InvokeMember("Name", Reflection.BindingFlags.SetProperty Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance, Nothing, dlg, New Object() {"C:\Documents and Settings\My Documents\MailMerge\"}, System.Globalization.CultureInfo.InvariantCulture)
Dim timeOut As Object = 0
Dim a As Int16 = dlg.Show(timeOut)
'if a document has been opened.
If (a = -1) Then
oDoc = oWord.ActiveDocument
oDoc.Select()
oDoc.MailMerge.OpenDataSource("C:\\usr\\mergequery.txt", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
oDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
oDoc.MailMerge.Execute(oFalse)
'Close the original form document.
oDoc.Saved = True
oDoc.Close(oFalse, oMissing, oMissing)
End If
I have this snippet of VB.NET code that I want to convert to VBScript. It basically starts Microsoft Word, displays the Open dialog and mail merges the selected document. Any help will be highly appreciated.
Dim oMissing As Object = System.Reflection.Missing.Value
Dim oEndOfDoc As Object = "\\endofdoc"
Dim oFalse As Object = False
'Start Word and create a new document.
Dim oWord As Word._Application
Dim oDoc As Word._Document
oWord = New Word.Application()
oWord.Visible = True
'show box
Dim dlg As Word.Dialog = oWord.Dialogs(Word.WdWordDialog.wdDialogFileOpen)
Dim dlgType As System.Type = GetType(Word.Dialog)
' Set the Name property of the dialog box.
dlgType.InvokeMember("Name", Reflection.BindingFlags.SetProperty Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance, Nothing, dlg, New Object() {"C:\Documents and Settings\My Documents\MailMerge\"}, System.Globalization.CultureInfo.InvariantCulture)
Dim timeOut As Object = 0
Dim a As Int16 = dlg.Show(timeOut)
'if a document has been opened.
If (a = -1) Then
oDoc = oWord.ActiveDocument
oDoc.Select()
oDoc.MailMerge.OpenDataSource("C:\\usr\\mergequery.txt", oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
oDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
oDoc.MailMerge.Execute(oFalse)
'Close the original form document.
oDoc.Saved = True
oDoc.Close(oFalse, oMissing, oMissing)
End If
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
干得好。
Here you go.
这将在 VBscript 中打开文档:
This is will open the doc in VBscript: