注册 登录
编程论坛 VB6论坛

求助-VB6控制Word中插入的电子表格

huwenyi7758 发布于 2015-08-08 14:22, 515 次点击
Dim WordApp As Object, worddoc As Object
Private Sub Command5_Click()
   Dim L1 As Double, L2 As Double, L3 As Double
   Dim wrdDoc  'Modify
   Dim wrdPic  'Modify
   L1 = Text11.Text
   L2 = Text12.Text
   L3 = Text13.Text
   Label54.Caption = L1 + L2 + L3
   Label55.Caption = L1 * L2 * L3
   Label58.Caption = Text9.Text
   Label59.Caption = Text10.Text
   Dim wordObj
   Set wordObj = CreateObject("Word.Application")
   Set wrdDoc = wordObj.Documents.Open("E:\编程\##\##.docx") 'Modify
   With wrdDoc 'Modify
   'With wordObj.Documents.Open("E:\编程\##\##.docx")
     CommonDialog1.Filter = "Word文档(*.docx)|*.docx" '存储文件
     CommonDialog1.ShowSave
     If CommonDialog1.FileName = "" Then
       K1 = 3
     Else
       With .Content
         .Find.MatchCase = True
         .Find.Execute "{cd1}", , , , , , , , , Text11, 2
         .Find.Execute "{cd2}", , , , , , , , , Text12, 2
         .Find.Execute "{cd3}", , , , , , , , , Text13, 2
         .Find.Execute "{cd4}", , , , , , , , , Label54, 2
         .Find.Execute "{cd5}", , , , , , , , , Label55, 2
         .Find.Execute "{cd6}", , , , , , , , , Label58, 2
         .Find.Execute "{cd7}", , , , , , , , , Label59, 2
       End With
 Set wrdPic = wrdDoc.Shapes.AddPicture(FileName:="C:\Users\Administrator\Desktop\捕获.GIF", LinkToFile:=False, SaveWithDocument:=True, Left:=wrdShapeCenter, Top:=100)     'Modify
   
       .SaveAs CommonDialog1.FileName
     End If
   End With
   wordObj.Quit
 End Sub
该程序可以把我E:\编程\##\##.docx里面的{cd1}-{cd7}替换成了我算好的数据并选择另存为新的word文件,且插入图片。 但是我现在要在E:\编程\##\##.docx里面插入了一个电子表格,注意是2007版word里面插入“电子”表格,然后我想在表格里面先输入{cd1}-{cd7},想和我前面程序那样一样的替换出来我想要的数据然后保存一个新word不知道可否。。如若没有办法这样替换,可否有什么办法程序插入表格,并同理要在表格内输入text12.text-label59.caption已经算好的数值。在我原程序里面该加些什么,求大神帮忙谢谢!
2 回复
#2
huwenyi77582015-08-10 08:07
竟然没人。。
#3
china_shy_wz2020-06-05 16:57
学习学习
1