有网友 知道 如何用VBA 向WORD 中写入 文档吗

yunong11 2001-04-23 11:26:00
您好,知道 如何用VBA 向WORD 中写入 文档吗,同时写入图片入WORD
同时控制不同行的字体大小
如果哪位网友知道的话,请多多帮忙阿,谢谢了
有源代码说明最好 麻烦您了

希望这里的论坛成为 我们共同学习的好地方
...全文
318 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuxing23 2001-04-24
  • 打赏
  • 举报
回复
上面的源代码是从数据库查出来 传到word 中的
如没有数据库
可以把数据库查询的地方不要
liuxing23 2001-04-24
  • 打赏
  • 举报
回复
Private Sub Command2_Click()

Dim appid, returnvalue
Screen.MousePointer = 11 '新设屏幕鼠标指针
Set msword = CreateObject("word.basic") '创建对象msword
appid = Shell("C:\Program Files\Microsoft Office\Office\winword.exe", 0)
msword.AppActivate "microsoft word" '启动microsoft word
datatrans '调用数据传递过程
Screen.MousePointer = 0 '恢复屏幕鼠标设置
msword.fileprint
End Sub


Sub datatrans()
Dim i As Integer, j As Integer, col As Integer, row As Integer
Dim cellcontent As String
Me.Hide '隐藏vb窗体
Cols = 7 '表格的列数
rows = 50 '........行数
'创建word 文件与其中的报表
msword.filenewdefault
msword.MsgBox "wait a moment", "", -1

msword.screenupdating 1
msword.tableinserttable , Cols, rows, , , 16, 167
msword.startofdocument
For k = 1 To Cols
msword.Insert cellcontent$
msword.nextcell
Next k
'将datagrid中的数据传递到word 报表中
Adodc1.Recordset.MoveFirst
jj = 0
Do While Adodc1.Recordset.EOF() = False
jj = jj + 1
For i = 0 To Cols - 1
DataGrid1.col = i
If IsNull(DataGrid1.Text) Then
cellcontent$ = ""
Else
cellcontent$ = DataGrid1.Text
End If
msword.Insert cellcontent$
msword.nextcell
Next i
If jj = 40 Then '用于控制传递数据的总行数
Exit Do

End If
Adodc1.Recordset.MoveNext
Loop
msword.Tabledeleterow
msword.startofdocument
msword.tableselectrow
msword.tableheadings 1
msword.centerpara
msword.screenrefresh
msword.screenupdating 1
msword.MsgBox "end", "", -1
Me.Show '显示被隐藏的vb窗体
End Sub




Private Sub Form_Load()
Dim rs As Recordset
Adodc1.RecordSource = "select room_no ,room_large,room_name ,room_mode,room_time1,room_time2,room_time3 from _test_room"
Adodc1.Refresh
Set rs = Adodc1.Recordset
'DataGrid1.DataSource = Adodc1
End Sub
binghuodao 2001-04-24
  • 打赏
  • 举报
回复
见vbawrd8.hlp,安装盘里有
ciml 2001-04-24
  • 打赏
  • 举报
回复
在word录制宏,看代码就知道了
yunong11 2001-04-24
  • 打赏
  • 举报
回复
to liuxing23(流星):你好,有没有 visual basic for application 的例子
word basic 好像老了一点
感谢您的帮助
to ciml(镜子) :你的方法好像不错,让我好好
研究一下,谢谢您
to binghuodao(冰火岛) :好像是 Vbabdr8.hlp .谢谢您


2,506

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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