用VB如何在WORD指定位置上插入文字?
在VB6.0中,操作word,使用它强大的查找、替换、删除、复制、翦切功能。
还可以把特定字符替换成图片。
有了它你就可以使用数据库中的内容或图片文件替换word文件中的特定字符。
只要把下列内容复制到写字板中,另存为SetWord.cls文件,然后在把它添加到工程中,就可以使用了。
VERSION 1.0 CLASSBEGINMultiUse = -1 'TruePersistable = 0 'NotPersistableDataBindingBehavior = 0 'vbNoneDataSourceBehavior = 0 'vbNoneMTSTransactionMode = 0 'NotAnMTSObjectENDAttribute VB_Name = "SetWord"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = TrueAttribute VB_PredeclaredId = FalseAttribute VB_Exposed = FalsePrivate mywdapp As Word.ApplicationPrivate mysel As Object'属性值的模块变量Private C_TemplateDoc As StringPrivate C_newDoc As StringPrivate C_PicFile As StringPrivate C_ErrMsg As IntegerPublic Event HaveError()Attribute HaveError.VB_Description = "出错时激发此事件.出错代码为ErrMsg属性"'***************************************************************'ErrMsg代码:1-word没有安装 2 - 缺少参数 3 - 没权限写文件' 4 - 文件不存在''***************************************************************Public Function ReplacePic(FindStr As String, Optional Time As Integer = 0) As IntegerAttribute ReplacePic.VB_Description = "查找FindStr,并替换为PicFile所指向的图片文件,替换次数由time参数确定,为0时,替换所有"'********************************************************************************' 从Word.Range对象mysel中查找所有FindStr,并替换为PicFile图像' 替换次数由time参数确定,为0时,替换所有'********************************************************************************If Len(C_PicFile) = 0 ThenC_ErrMsg = 2Exit FunctionEnd IfDim i As IntegerDim findtxt As Booleanmysel.Find.ClearFormattingmysel.Find.Replacement.ClearFormattingWith mysel.Find.Text = FindStr.Replacement.Text = "".Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd Withmysel.HomeKey Unit:=wdStoryfindtxt = mysel.Find.Execute(Replace:=True)If Not findtxt ThenReplacePic = 0Exit FunctionEnd Ifi = 1Do While findtxtmysel.InlineShapes.AddPicture FileName:=C_PicFileIf i = Time Then Exit Doi = i + 1mysel.HomeKey Unit:=wdStoryfindtxt = mysel.Find.Execute(Replace:=True)LoopReplacePic = iEnd FunctionPublic Function FindThis(FindStr As String) As BooleanAttribute FindThis.VB_Description = "查找FindStr,如果模板中有FindStr则返回True"If Len(FindStr) = 0 ThenC_ErrMsg = 2Exit FunctionEnd Ifmysel.Find.ClearFormattingmysel.Find.Replacement.ClearFormattingWith mysel.Find.Text = FindStr.Replacement.Text = "".Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd Withmysel.HomeKey Unit:=wdStoryFindThis = mysel.Find.ExecuteEnd FunctionPublic Function ReplaceChar(FindStr As String, RepStr As String, Optional Time As Integer = 0) As IntegerAttribute ReplaceChar.VB_Description = "查找FindStr,并替换为RepStr,替换次数由time参数确定,为0时,替换所有"'********************************************************************************' 从Word.Range对象mysel中查找FindStr,并替换为RepStr' 替换次数由time参数确定,为0时,替换所有'********************************************************************************Dim findtxt As BooleanIf Len(FindStr) = 0 ThenC_ErrMsg = 2RaiseEvent HaveErrorExit FunctionEnd Ifmysel.Find.ClearFormattingmysel.Find.Replacement.ClearFormattingWith mysel.Find.Text = FindStr.Replacement.Text = RepStr.Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = True.MatchWildcards = False.MatchSoundsLike = False.MatchAllWordForms = FalseEnd WithIf Time > 0 ThenFor i = 1 To Timemysel.HomeKey Unit:=wdStoryfindtxt = mysel.Find.Execute(Replace:=wdReplaceOne)If Not findtxt Then Exit ForNextIf i = 1 And Not findtxt ThenReplaceChar = 0ElseReplaceChar = iEnd IfElsemysel.Find.Execute Replace:=wdReplaceAllEnd IfEnd FunctionPublic Function GetPic(PicData() As Byte, FileName As String) As BooleanAttribute GetPic.VB_Description = "把图像数据PicData,存为PicFile指定的文件"'********************************************************************************' 把图像数据PicData,存为PicFile指定的文件'********************************************************************************On Error Resume ...
如何用VB.net控制word中文字的行间距
应该是没有的对于某个编程语言的某块调用翻来覆去最多也就是10几句20几句的指令,出一本书成本太大,购买的人又少,肯定不会出。
除非像数据库之类的东西这种东西应该在API的书或者专门讲ocx调用的书里会讲,但是ocx一直是个冷门还是建议百度吧
vb 如何访问word中的嵌套表格
展开全部 如下的方法请参考: 首先打开VB软件,在新建工程对话框中选择“标准exe”,点击打开按钮。
进入工程》》引用菜单。
在引用对话框中找到MicroSoft Word 11.0 Object Library然后勾选,当然我这里是MicroSoft Word 14.0 Object Library,都无所谓。
在窗口中添加一个按钮,将文字改为“生成word”。
双击生成“生成word”按钮,进入代码编辑区,输入下列代码。
按F8,运行程序。
点击“生成word”按钮,是不是跳出word了先关掉刚才生成的word,然后再输入以下代码,然后运行程序。
...
转载请注明出处51数据库 » vb控制word文档插入文字
战无不胜oooo