vb如何操作word文档

hengkongshi 2008-12-19 06:24:04
请问哪位高手知道在vb中如何操作word文档。我想达到的要求是:在vb中输出数据到word文档中(未建好的文档)。最好是有现成的完整的代码,在此先谢过各位了!急需!!谢谢!!!
...全文
96 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hengkongshi 2009-01-12
  • 打赏
  • 举报
回复
不是,想当兵来着,可惜视力不达标,呵呵……
mfkinfo 2009-01-02
  • 打赏
  • 举报
回复
1、引用word类,我用的是Microsoft word 11.0 object library(11.0为版本号,安装的office版本不同而不同)。
2、设置word程序对象:Dim owdApp As Word.Application或Dim owdapp As New Word.Application(直接创建新对象)
3、添加新文档:Set oWdActiveDoc = owdApp.Documents.Add()
4、由数据库里按要求提取数据并写入文档:
内容太多不写了,可以参阅word的宏录入和宏编辑以及它所提供的帮助,也无外乎是选择一个区域(selection),把值赋予它或设值它的格式。
5、保存退出。If Not oWdActiveDoc Is Nothing Then oWdActiveDoc.SaveAs filename:=strTname
6、关闭对象set owdactivedoc =nothing: set owdapp=nothing

http://blog.csdn.net/mfkinfo/archive/2009/01/02/3686625.aspx
noenoughmemory 2008-12-29
  • 打赏
  • 举报
回复
不懂,帮顶
terrywolf 2008-12-29
  • 打赏
  • 举报
回复
不懂,顶一下,
楼主是兵哥哥?
gutou0389 2008-12-20
  • 打赏
  • 举报
回复
Dim w1 As Word.Application

Set w1 = New Word.Application
w1.Documents.Add
w1.Visible = True

w1.Selection.Font.Size = 15
w1.Selection.Font.NameFarEast = "黑体"
w1.Selection.Font.NameAscii = "黑体"
' w1.Selection.Font.NameOther = "黑体"
w1.Selection.Font.Bold = 1
w1.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
w1.Selection.TypeParagraph
w1.Selection.TypeText "提前还款通知书(会计联)"
w1.Selection.TypeParagraph

'格式设置
'=======================
With w1.ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With w1.ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2)
.BottomMargin = CentimetersToPoints(2)
.LeftMargin = CentimetersToPoints(2.17)
.RightMargin = CentimetersToPoints(2.17)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5)
.FooterDistance = CentimetersToPoints(1.75)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LayoutMode = wdLayoutModeLineGrid
End With
With w1.Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.AutoAdjustRightIndent = True
.DisableLineHeightGrid = False
.FarEastLineBreakControl = True
.WordWrap = True
.HangingPunctuation = True
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True
.AddSpaceBetweenFarEastAndDigit = True
.BaseLineAlignment = wdBaselineAlignAuto
.LineSpacing = LinesToPoints(1.5) '行宽
End With


w1.Selection.Font.Size = 10
w1.Selection.Font.NameFarEast = "宋体"
w1.Selection.Font.NameAscii = "宋体"
w1.Selection.Font.NameOther = "宋体"
w1.Selection.PageSetup.BottomMargin = CentimetersToPoints(1.7)
w1.Selection.PageSetup.TopMargin = CentimetersToPoints(1.7)
w1.Selection.Font.Size = 10
w1.Selection.Font.Bold = 0

w1.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
'正文


w1.Selection.TypeText " 编号:"
Call c_c(" 66666666666666 ", w1) '编号
w1.Selection.TypeParagraph


w1.Selection.TypeText "会计部门:"
w1.Selection.TypeParagraph
w1.Selection.TypeText " 根据客户与我行签订的《借款合同》及提前还款的申请,现将提前还款的有关事项通知如下:"
w1.Selection.TypeParagraph



创建新word文档


1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧