不知道你要利用VB还是Word的VBA实现,最方便的方法是利用Word的宏,首先打开模板,然后
开始录制宏(alt+f8),执行你需要程序做的操作,然后停止,打开VBA编辑器,就可以看到
你录制的宏相对应得VBA代码,这些代码如果是在VBA中使用,基本不需要做修改,在VB中使用
也只需要做小的改动,例如Word初始化等等。
开始录制宏(alt+f8),执行你需要程序做的操作,然后停止,打开VBA编辑器,就可以看到
你录制的宏相对应得VBA代码,这些代码如果是在VBA中使用,基本不需要做修改,在VB中使用
也只需要做小的改动,例如Word初始化等等。
我想剩下的你就应当知道了吧!!不同的东西对应不同的背替换内容。怎么样,但愿以上内容对你有帮助!
通过在模板中建立书签的方式标记所有用户可能需要设置的文本插入点,在wizard中由用户给标签设置插入的文本,字体等等,然后在程序打开模板,控制在书签中写入对应的内容并设置格式。
不过可以给你想一个折中的方案其实也是工作量不小的。前提是不用安装Word!
就是将所有需要生成的文章生成一个文本文件当然这个文本文件中还有一些只有你的程序能读懂的信息,比如字体、字号等等。然后再到其他有Word的机器上进行合成,这样就可以实现你的想法了,不过你要在没有Word的机器上应用Word我想这不是一个好主意!小心Ms的人和你拼命!在我写以上方案时,我想可以借助HTML语言。因为word支持HTML,而HTML又是文本的东东,所以我想你可以先生成一个网页文件(其中那些控制不用说了吧,其实我也不会反正就是加上那些 <html></html>东西)然后再用Word打开就可以,怎么样是不是想请我当你的顾问了?哈哈!!祝你好运!!!!
怎么样是不是想请我当你的顾问了?哈哈!! ok, 没问题!
有没有例子代码什么的? 看你这顾问够不够资格!! hehe 开玩笑,多谢!
我的文档是RTF格式,不是word,所以不怕MS, hehe
不过我想如果用html格式还真的能解决你的问题,因为那些东西都是文本操作,也不用到处找写法,最重要的是Word可以直接打开,字体、字号都可以设置,什么都是现成的,而且还不用Word的宏,越想越合适!
难道文本操作的代码还要?去找msdn吧,因为我这里也没有,唉见笑了!
Dim FoundIt As Boolean
Dim Xstart As Integer
Dim Xend As Integer
Dim textSel As String
Dim txtRate As String
Dim txtNo As String
Dim Rating(4) As Integer
Dim Senten(7) As StringPrivate Sub ButtonEx1_Click() ButtonEx1.Value = DownEnd SubPrivate Sub Command1_Click()
On Error GoTo woops
Dim sfile As String
With CommonDialog1
.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer + cdlOFNFileMustExist + cdlOFNHideReadOnly
.DialogTitle = "Open File"
.CancelError = True 'if the user cancels sends us to woops
.Filter = "Text files (*.rtf;*.txt)|*.rtf;*.txt|All files|*.*"
.ShowOpen
If Len(.FileName) = 0 Then Exit Sub
sfile = .FileName
End With
RTB.LoadFile sfile
CurrentFile = sfile 'used by the mod to save changes made
woops: Exit Sub
End SubFunction FindIt(RTF As RichTextBox, txt As String) As Integer
RTF.Refresh
'RTF.Find (Txt,0)
textfound = RTF.Find(txt, 0)
If textfound <> -1 Then
FoundIt = True 'lets the form know we found it
'RTF.SetFocus 'OK we've found it so select it to show the user
FindIt = RTF.SelStart
Exit Function 'lets' get out of here
Else
FoundIt = False 'lets the form know we cant find it
Exit Function
End If
End Function
Function FinditNext(RTF As RichTextBox, txt As String) As Integer
'the text has already been found once. We want the next occurrence
textfound = RTF.Find(txt, RTF.SelStart + Len(txt))
If textfound <> -1 Then 'Found it !
FoundIt = True 'let the form know we succeeded
'RTF.SetFocus 'show it to the user
FinditNext = RTF.SelStart
Exit Function 'lets bail out now
Else
FoundIt = False 'let the form know we cant find it
Exit Function 'lets bail out now
End IfEnd FunctionPrivate Sub Command2_Click()
Xstart = FindIt(RTB, txtFind.Text)End SubPrivate Sub Command3_Click()
Xend = FinditNext(RTB, txtFind.Text)
End SubPrivate Sub Command4_Click()
RTB.SelStart = Xstart
RTB.SelLength = Xend + 4 - Xstart
RTB.SelBold = True
RTB.SelColor = &HFFC0FF
RTB.SelUnderline = True
RTB.SelText = "I have changed the comapny Name"
'RTB.Visible = True
End SubPrivate Sub Command5_Click()
Label2.Caption = "Processing Please wait........."
Dim tempTxt As String
Dim temSent As String
Dim i As Integer
Dim j As Integer
For j = 1 To 6
tempTxt = "/PCI" & j & "R#" & txtFind.Text & "\"
BoldOpt RTB, tempTxt
tempTxt = "/PCI" & j & "R#"
ClearMark RTB, 5, tempTxt
tempTxt = "/PCI" & j & "N#" & Rating(txtFind.Text - 1) & "\"
BoldOpt RTB, tempTxt
tempTxt = "/PCI" & j & "N#"
ClearMark RTB, 10, tempTxt
For i = 1 To 8
tempTxt = "/PCI" & j & "S#" & i & "\"
temSent = Senten(i - 1)
FillSent RTB, tempTxt, temSent
Next i
Next j
DoEvents
RTB.Visible = True
End Sub
Sub ClearMark(RTF As RichTextBox, TotlNo As Integer, txt As String)
Dim txtTemp As String
Dim txtSel As String
Dim StartP As Long
Dim EndP As Long
Dim L As Long
Dim i As Integer
For i = 1 To TotlNo
txtTemp = txt & i & "\"
L = Len(txtTemp)
StartP = FindIt(RTF, txtTemp)
If FoundIt = True Then
EndP = FinditNext(RTF, txtTemp)
RTF.SelStart = StartP + L
RTF.SelLength = EndP - L - StartP
txtSel = RTF.SelText
RTF.SelStart = StartP
RTF.SelLength = EndP + L - StartP
RTF.SelText = txtSel
End If
Next i
End SubPrivate Sub Command6_Click()
On Error GoTo woops
Dim ssfile As String
With CommonDialog1
.DialogTitle = "Save File"
.CancelError = True 'if the user cancels sends us to woops
.Filter = "Text files (*.rtf;*.doc)|*.rtf;*.doc|All files|*.*"
.ShowOpen
If Len(.FileName) = 0 Then Exit Sub
ssfile = .FileName
End With
RTB.SaveFile ssfile
'CurrentFile = sfile 'used by the mod to save changes made
woops: Exit Sub
End SubPrivate Sub Form_Load()
Timer1.Enabled = False
'RTB.Visible = False
Rating(0) = 10
Rating(1) = 8
Rating(2) = 6
Rating(3) = 3
Rating(4) = 1
'Senten(0) = " "
'Senten(1) = " "
'Senten(2) = " "
'Senten(3) = " 6 "
'Senten(4) = " "
'Senten(5) = " 4.2 "
'Senten(6) = " 4.2 "
'Senten(7) = " "End SubSub BoldOpt(RTF As RichTextBox, txt As String)
Dim StartP As Long
Dim EndP As Long
Dim L As Integer
Dim txtSel As String
StartP = FindIt(RTF, txt)
EndP = FinditNext(RTF, txt)
If FoundIt = False Then Exit Sub
L = Len(txt)
RTF.SelStart = StartP + L
RTF.SelLength = EndP - L - StartP
txtSel = RTF.SelText
RTF.SelStart = StartP
RTF.SelLength = EndP + L - StartP
RTF.SelBold = True
RTF.SelText = txtSel
End Sub
Sub FillSent(RTF As RichTextBox, txt As String, txtChange As String)
Dim StartP As Long
Dim EndP As Long
Dim L As Integer
StartP = FindIt(RTF, txt)
If FoundIt = False Then Exit Sub
EndP = FinditNext(RTF, txt)
L = Len(txt)
RTF.SelStart = StartP
RTF.SelLength = EndP + L - StartP
'RTF.SelBold = True
RTF.SelUnderline = True
RTF.SelText = txtChange
End Sub
还是祝你成功,以你的功底改成HTML不成问题的!!祝你成功!!
另外顾问我是没有脸当了!!你另请高明吧! *_*
没写字体,字号的部份,就是插入,和将特定句子变成粗体。顾问当不当无所谓,是朋友就行了, 还是帮我考虑考虑。大家讨论讨论吗?给我点启发。
还是因为程序看得粗,不一定对,见谅!!
but Thank U anyway.
http://www.csdn.net/Expert/topic/497/497652.shtm
我刚刚生成了一个RTF文件的文档分析了一下,当然分析的不是特别透彻
但是感觉上不如HTML来得简单,而且好像有VB下有控制HTML文件的控件,你可以找一找(VB本身好像就有)祝你早日解决问题