使用Visual Basic自动化Word 2010模板 [英] Automating a word 2010 template with Visual Basic

查看:175
本文介绍了使用Visual Basic自动化Word 2010模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,继续我的冒险之旅我了解到使用模板会更容易,因为我在模板中创建了书签的问题.我可以打开模板,但是在书签所在的位置,我无法从程序中的文本框中获取数据来显示.我在做什么错了嘻嘻是我的代码:

Ok Continuint my venture I learned it would be easier to use a template this the problem I created a bookmark within my template. I can get the template open but where the bookmark is I can not get the data from a textbox in my program to show. What am I doing wrong hee is my code:

               Dim oWord As Microsoft.Office.Interop.Word.Application
               Dim oDoc As Microsoft.Office.Interop.Word.Document

'Start word Document template
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add("C:\Program Files\QC7\Field Quality Report.dotm")

        oDoc.Bookmarks.Item("District").Range.Text = Customer_Data.CustomerTextBox.Text

        oDoc = Nothing
        oWord = Nothing
        GC.Collect()
        GC.WaitForPendingFinalizers()
        GC.Collect()
        GC.WaitForPendingFinalizers()


        'All done
        Me.Hide()

推荐答案

很简单,您只是忘记添加一些必要的代码:
http://msdn.microsoft.com/en-us/library/ad6ks7k0%28v = vs.80%29.aspx [ ^ ]

Its pretty straight forward, you just forgot to add some nessecary code:
http://msdn.microsoft.com/en-us/library/ad6ks7k0%28v=vs.80%29.aspx[^]

object rng = bookmark.Range;
string bookmarkName = bookmark.Name;

bookmark.Range.Text = newText;

this.Bookmarks.Add(bookmarkName, ref rng);


这篇关于使用Visual Basic自动化Word 2010模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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