vb如何将数据保存到word中,并打印

编个小程序,想要实现单击"保存"command时,将程序运行出来的数据保存至word中,单击"打印"command时,将此word文件打印出来.请高手赐教!谢谢哦... 编个小程序,想要实现单击"保存"command时,将程序运行出来的数据保存至word中,单击"打印"command时,将此word文件打印出来.请高手赐教!谢谢哦 展开
 我来答
甲虫tony
2008-12-11 · TA获得超过288个赞
知道小有建树答主
回答量:307
采纳率:0%
帮助的人:344万
展开全部
在窗体上放11个控件

Dim WordApp As Word.Application
Dim ThisDocument As Word.Document

Private Sub Command1_Click()
On Error Resume Next
ChangeFileOpenDirectory App.Path
Documents.Open FileName:=App.Path + "\help.doc", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto, XMLTransform:=""

Windows("help.doc").Activate
Selection.TypeBackspace
Application.WindowState = wdWindowStateNormal
ActiveDocument.Shapes.AddTextEffect(msoTextEffect16, "请在此键入您自己的艺术字内容", _
"宋体", 36#, msoFalse, msoFalse, 46.1, 159.35).Select
End Sub

Private Sub Command2_Click()
On Error Resume Next
Windows("help.doc").Close
ActiveWindow.Close
WordApp.Application.Quit
End Sub

Private Sub Command3_Click()
On Error Resume Next
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
Set ThisDocument = WordApp.Documents.Add
ThisDocument.Activate
End Sub

Private Sub Command4_Click()
On Error Resume Next
Selection.MoveRight Unit:=wdCell
ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, FileName:= _
"C:\Program Files\Microsoft Office\MEDIA\OFFICE11\AutoShap\BD18181_.wmf", _
LinkToFile:=False, SaveWithDocument:=True).WrapFormat.Type = _
wdWrapInline
Selection.ShapeRange.IncrementLeft 208.9
Selection.ShapeRange.IncrementTop 18.65
ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, FileName:= _
"C:\Program Files\Microsoft Office\MEDIA\OFFICE11\AutoShap\BD18185_.wmf", _
LinkToFile:=False, SaveWithDocument:=True).WrapFormat.Type = _
wdWrapInline
Selection.ShapeRange.IncrementLeft 181.5
Selection.ShapeRange.IncrementTop 71.85
ActiveWindow.ActivePane.VerticalPercentScrolled = 41
Selection.ShapeRange.IncrementLeft 9#
Selection.ShapeRange.IncrementTop 7.8
CommandBars("AutoShapes").Visible = False
ActiveWindow.ActivePane.VerticalPercentScrolled = 25
Application.WindowState = wdWindowStateMinimize
Application.WindowState = wdWindowStateNormal
ActiveWindow.ActivePane.VerticalPercentScrolled = 54
Selection.InlineShapes.AddPicture FileName:= _
App.Path + "\20041204150550.jpg", LinkToFile:=False, _
SaveWithDocument:=True
ActiveDocument.Shapes("computr1").Select
Selection.ShapeRange.IncrementLeft -27#
Selection.ShapeRange.IncrementTop 117#
ActiveDocument.Shapes("cddrive").Select
Selection.ShapeRange.IncrementLeft 212.6
Selection.ShapeRange.IncrementTop 272#

End Sub

Private Sub Command5_Click()
On Error Resume Next
Selection.TypeText Text:="表格"
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Font.Size = 26
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.Font.Size = 12
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=10, NumColumns _
:=5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.TypeText Text:="1"
Selection.TypeParagraph
Selection.TypeBackspace
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="2"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="3"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="4"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="5"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="6"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="7"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="8"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="9"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="10"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="11"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="12"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="13"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="14"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="15"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="16"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="17"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="18"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="19"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="20"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="21"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="22"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="23"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="24"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="25"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="26"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="27"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="28"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="29"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="30"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="31"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="32"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="33"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="34"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="35"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="36"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="37"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="38"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="39"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="40"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="41"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="42"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="43"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="44"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="45"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="46"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="47"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="48"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="49"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="50"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCharacter, Count:=5, Extend:=wdExtend
Selection.Cells.Merge
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCell
End Sub

Private Sub Command6_Click()
On Error Resume Next
ActiveDocument.PrintPreview '打印预览
End Sub

Private Sub Command7_Click()
On Error Resume Next
Selection.MoveUp Unit:=wdLine, Count:=22
ActiveDocument.Shapes.AddTextEffect(msoTextEffect16, "请在此键入您自己的艺术字内容", _
"宋体", 36#, msoFalse, msoFalse, 46.1, 159.35).Select
ActiveWindow.ActivePane.VerticalPercentScrolled = 24
Selection.MoveRight Unit:=wdCell
End Sub

Private Sub Command8_Click()
On Error Resume Next
Application.WindowState = wdWindowStateMinimize
End Sub

Private Sub Command10_Click()
On Error Resume Next
ActiveDocument.PrintOut '直接打印
Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Item:= _
wdPrintDocumentContent, Copies:=5, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0 '设置后打印
End Sub

Private Sub Command11_Click()
On Error Resume Next
Application.WindowState = wdWindowStateNormal
End Sub

Private Sub Command9_Click()
On Error Resume Next
Application.WindowState = wdWindowStateMaximize
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式