急!用VB实现一个打印WORD文档功能。。。
VB实现一个打印WORD文档功能,用代码实现在word模板中的指定位置添加文字,然后打印选项可以通过commondialog控件实现,之后直接打印此填完后的WORD模板。...
VB实现一个打印WORD文档功能,用代码实现在word模板中的指定位置添加文字,然后打印选项可以通过commondialog控件实现,之后直接打印此填完后的WORD模板。请给出参考代码,答的好的有大量追加分!
没有我想要的答案! 2楼的 正因为邮件合并功能操作太麻烦,所以采用VB来实现;3楼的 合同模板是DOC里面准备好的,我要做的就是往相应的空白处添加具体内容就行,不需要在VB里重新设计模板.... 展开
没有我想要的答案! 2楼的 正因为邮件合并功能操作太麻烦,所以采用VB来实现;3楼的 合同模板是DOC里面准备好的,我要做的就是往相应的空白处添加具体内容就行,不需要在VB里重新设计模板.... 展开
7个回答
展开全部
VB实现打印WORD文档功能的思路如下:
一、设计一个打印模板文件,在需要填写数据的地方作标记;
二、在打印前,可复制模板文件到一个临时文件,然后打开此临时模板文件,在标记处通过替换功能填写数据。
三、显示打印选项对话框,进行打印输出。
以下是示例源代码,请下载参考:
http://files.7lx.com/data/2010-09/2010september18th165312_word_print.rar
一、设计一个打印模板文件,在需要填写数据的地方作标记;
二、在打印前,可复制模板文件到一个临时文件,然后打开此临时模板文件,在标记处通过替换功能填写数据。
三、显示打印选项对话框,进行打印输出。
以下是示例源代码,请下载参考:
http://files.7lx.com/data/2010-09/2010september18th165312_word_print.rar
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
展开全部
先做好word模板文件,把需要用VB来操作的地方留置特定格式的标识符号,用VB操作word的替换功能来替换相应位置的文字
或者说在vb中把需要在word文件出现的文字全部拼接后再写入word
或者说在vb中把需要在word文件出现的文字全部拼接后再写入word
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
添加必要的按钮和文本框,ChMoney()函数没有粘贴,可以把相关的语句删除
Private Sub Command1_Click()
Dim ctrl As Control
For Each ctrl In Controls
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Then
If ctrl.Text = "" Then Exit Sub
End If
Next
End If
On Error GoTo errHandler:
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Add
With objWord
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Size = 36
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).SpaceAfter = 7.8
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Bold = True
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Name = "宋体"
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Alignment = 1 '居中对齐
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "证 明"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).LineSpacingRule = 4
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).lineSpacing = 55
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).SpaceBefore = 0
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).SpaceAfter = 0
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Size = 22
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Bold = False
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Name = "宋体"
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Alignment = 0 '居中对齐
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "县国税局:"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 2
TotalPrice = Format(Val(txtPrice) * Val(txtWeight), "00.00") '总价
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = _
"今有" + CStr(txtCustom) + "销给我公司" + CStr(txtGoods) + _
CStr(txtWeight) + "吨,单价" + CStr(txtPrice) + "元/吨,计款" + _
CStr(ChMoney(TotalPrice)) + "整,小写¥" + TotalPrice + _
"。请予办理纳税手续为盼。"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 2.5
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "特此证明!"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Size = 18
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).LineSpacingRule = 4
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).lineSpacing = 40
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 8.5
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "固安县永丰新型建材有限公司"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 10.5
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = CStr(Year(Date)) + "年" + _
CStr(Month(Date)) + "月" + _
CStr(Day(Date)) + "日"
With .ActiveDocument.PageSetup
.TopMargin = 120 '1磅=0.035厘米
.BottomMargin = 90
.LeftMargin = 85
.RightMargin = 85
End With
'县国税局:TypeParagraph
.ActiveDocument.saved = True
End With
If MsgBox("确定打印?", vbYesNo) = vbYes Then
objWord.ActiveDocument.printout
objWord.quit
End If
Set objWord = Nothing
errHandler: '错误处理
MsgBox Err.Description + vbCrLf + "错误号:" + CStr(Err.Number), vbCritical, "出错"
Set objWord = Nothing
Exit Sub
End Sub
Private Sub Command1_Click()
Dim ctrl As Control
For Each ctrl In Controls
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Then
If ctrl.Text = "" Then Exit Sub
End If
Next
End If
On Error GoTo errHandler:
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Add
With objWord
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Size = 36
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).SpaceAfter = 7.8
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Bold = True
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Name = "宋体"
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Alignment = 1 '居中对齐
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "证 明"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).LineSpacingRule = 4
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).lineSpacing = 55
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).SpaceBefore = 0
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).SpaceAfter = 0
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Size = 22
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Bold = False
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Name = "宋体"
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Alignment = 0 '居中对齐
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "县国税局:"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 2
TotalPrice = Format(Val(txtPrice) * Val(txtWeight), "00.00") '总价
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = _
"今有" + CStr(txtCustom) + "销给我公司" + CStr(txtGoods) + _
CStr(txtWeight) + "吨,单价" + CStr(txtPrice) + "元/吨,计款" + _
CStr(ChMoney(TotalPrice)) + "整,小写¥" + TotalPrice + _
"。请予办理纳税手续为盼。"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 2.5
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "特此证明!"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Font.Size = 18
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).LineSpacingRule = 4
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).lineSpacing = 40
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 8.5
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = "固安县永丰新型建材有限公司"
.ActiveDocument.Paragraphs.Add
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).CharacterUnitFirstLineIndent = 10.5
.ActiveDocument.Paragraphs(.ActiveDocument.Paragraphs.Count).Range.Text = CStr(Year(Date)) + "年" + _
CStr(Month(Date)) + "月" + _
CStr(Day(Date)) + "日"
With .ActiveDocument.PageSetup
.TopMargin = 120 '1磅=0.035厘米
.BottomMargin = 90
.LeftMargin = 85
.RightMargin = 85
End With
'县国税局:TypeParagraph
.ActiveDocument.saved = True
End With
If MsgBox("确定打印?", vbYesNo) = vbYes Then
objWord.ActiveDocument.printout
objWord.quit
End If
Set objWord = Nothing
errHandler: '错误处理
MsgBox Err.Description + vbCrLf + "错误号:" + CStr(Err.Number), vbCritical, "出错"
Set objWord = Nothing
Exit Sub
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用 Visual Basic for Application 功能,引用Word,对Word进行二次开发。
关于Word二次开发的的资料,在网上很多。
好像是通过Word内置的功能来打印,用不上你的commondialog控件
关于Word二次开发的的资料,在网上很多。
好像是通过Word内置的功能来打印,用不上你的commondialog控件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这里注册一个用户去下载看看:
http://s.pudn.com/search_hot.asp?k=vB+%B4%F2%D3%A1#
http://s.pudn.com/search_hot.asp?k=vB+%B4%F2%D3%A1#
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询