怎样在WORD模板指定位置中添加文字
用VB编程实现在界面上输入的内容输出到WORD文档中设定好的指定位置上。
dim appwd As Word.Application
dim mydoc As Word.Document
dim arange As Word.Range
dim aselection As Word.SelectionSet appwd = CreateObject("word.application") '创建 word application 对象
With appwd
.Visible = False
Set mydoc = .Documents.Open(fpath) '调用word文档
mydoc.Activate
Set aselection = .Selection
Set arange = .ActiveDocument.Range(0, 1)
'Range(0, 1)为选取的插入点,须根据情况而定
arange.Select
arange.InsertAfter (mytext)
'或 arange.Insertbefore (mytext)'mytext为用VB编程实现在界面上输入的内容
用VB编程实现在界面上输入的内容输出到WORD文档中设定好的指定位置上。
dim appwd As Word.Application
dim mydoc As Word.Document
dim arange As Word.Range
dim aselection As Word.SelectionSet appwd = CreateObject("word.application") '创建 word application 对象
With appwd
.Visible = False
Set mydoc = .Documents.Open(fpath) '调用word文档
mydoc.Activate
Set aselection = .Selection
Set arange = .ActiveDocument.Range(0, 1)
'Range(0, 1)为选取的插入点,须根据情况而定
arange.Select
arange.InsertAfter (mytext)
'或 arange.Insertbefore (mytext)'mytext为用VB编程实现在界面上输入的内容
解决方案 »
- Picture中绘制的图像(手工绘的,Bitblt绘的,GDI+绘的都行),不经保存,如何直接从内存转化为一个Picture对象(StdPicture)?
- For Each...Next 的用法
- 请教一下高手 网站来路分析的原理是什么?
- 一个关于MYSQL的问题
- 怎么读取INI文件中的所有小节名?
- WebBrowser打开execl文件时没有象ie那样的execl工具栏和菜单,如何实现。
- 无效的类别字符串是什么错误??
- 用代码添加控件?怎么写?
- 有谁用过滚动条控件?
- vb安装的问题,在"安装程序正在搜索已安装的组件"停止
- 在 ActiveX 作了一个属性页 ,可是不能显示?求大师赐教
- 在查询时,怎么样把varchar转换成money型的数据?
是类似这样的么 :
文档定义:{ }
大括号对应一个域还有比如我要实现某一个域可能输入可能不输入,某一些域还可能存在循环,这都是值得分析的点
'在表格的特定行的特定列插入特定域
'*******************************Public Sub addFormFieldinTable(ByRef objDoc, ByRef addTable As Object, intRow As Integer, lngPosition As Long, lngClass As Long, _
lngType As Long, _
Optional strName As String = "", _
Optional strDefault As String = "", _
Optional strFormat As String = "", _
Optional strFunction As String = "", _
Optional lngWidth As Long = 0, _
Optional exitMacro As String, _
Optional bolIfEnable As String = "true", Optional strResult As String = "")
Dim fidAdd As Object
Dim inttype As Integer
Dim bolEnable As Boolean
Dim objSelection As Object
Dim objRange As Object
Dim intClass As Integer
Const c_RegularText = 0
Const c_NumberText = 1
Const c_CalculationText = 5
Const c_DateText = 2
Const c_TextFormField = 70
Const c_SelectFormField = 71
Dim m_Strfunction
bolEnable = True
Select Case lngClass
Case 1
intClass = c_TextFormField
Case 2
intClass = c_SelectFormField
End Select
Select Case lngType
Case 1
inttype = c_RegularText
Case 2
inttype = c_NumberText
Case 3
inttype = c_CalculationText
bolEnable = False
If strFunction = "" Then
Else
strDefault = strFunction
End If
Case 4
inttype = c_DateText
End Select
If bolIfEnable = "false" Then
bolEnable = False
End If
addTable.Cell(intRow, 1).Select
objDoc.Application.Selection.Move Unit:=12, Count:=lngPosition - 1 '12 -->wdcell
Set objRange = objDoc.Application.Selection.range
Set fidAdd = objDoc.FormFields.Add(range:=objRange, _
Type:=intClass) '70 -->wdFieldFormTextInput
With fidAdd
If strName = "" Then
Else
.Name = strName
End If
If lngClass = 1 Then
.TextInput.EditType Type:=inttype, Default:=strDefault, _
Format:=strFormat, Enabled:=bolEnable
If lngWidth <> 0 Then
.TextInput.Width = lngWidth
End If
.CalculateOnExit = True
If exitMacro <> "" Then
.exitMacro = exitMacro
End If
If strResult <> "" Then
.Result = strResult
End If
ElseIf lngClass = 2 Then
If exitMacro <> "" Then
.exitMacro = exitMacro
End If
If strResult <> "" Then
If strResult = "1" Then
.CheckBox.Value = True
Else
.CheckBox.Value = False
End If
End If
.Enabled = bolEnable
End If
End With
End Sub
vba关联,好像word的书签功能能够用来插入数据单现在不知道怎么用,谁能提供这两种方法任意一种都可以,不过谢谢楼上
vba关联,好像word的书签功能能够用来插入数据,但现在不知道怎么用,谁能提供这两种方法任意一种都可以,不过谢谢楼上
用如下代码,
call InsertOneBook objdoc,"aaa","bbb",strerror
其中aaa是书签名,bbb是书签内容
函数如下:
Public Function InsertOneBook(ByRef objDoc, ByVal strBookMark As String, _
ByVal strText As String, ByRef strError As String) As Boolean
Dim objMarks As Object
Dim BookRange As Object
InsertOneBook = False
Set objMarks = objDoc.Books
If Not objMarks.Exists(strBookMark) Then
strError = "没有找到BOOKMARK:" & strBookMark
GoTo ExitHandle
End If
Set BookRange = objMarks(strBookMark).range
BookRange.Text = strText
objMarks.Add strBookMark, BookRange
InsertOneBook = True
ExitHandle:
Set objMarks = Nothing
Set BookRange = NothingEnd Function
我写的一个通用组件,简直就是给你量体裁衣做的
如果你想了解较全面的内容,可以看一下我今天发的关于WORD通用组件的贴子