dH6KMYbZ.rar
(81.17 KB, 下载次数: 37)
Sub page1() Dim m, nrecord, txtnumber As Integer Dim i As Bookmark Set md = DBEngine.OpenDatabase("F:\study\db1.mdb") Set rs = md.OpenRecordset("car") Set mydoc1 = ActiveDocument Selection.WholeStory Selection.Copy Set mydoc2 = Documents.Add Selection.Paste On Error Resume Next rs.MoveLast nrecord = rs.RecordCount On Error GoTo doerror doerror: For m = 1 To nrecord If m = 1 Then rs.MoveFirst Else rs.MoveNext With rs mydoc2.Bookmarks("chead").Select With Selection.Font .Bold = wdToggle .NameAscii = "宋体" .NameFarEast = "宋体" .NameBi = "宋体" .Size = 10 .SizeBi = 10 .Underline = 0 .Color = wdColorBlack End With Selection.TypeText Text:=.Fields("chead") mydoc2.Bookmarks("ehead").Select With Selection.Font .Name = "Arial" .Size = 10 End With Selection.TypeText Text:=.Fields("ehead")
mydoc2.Bookmarks("pub").Select With Selection.Font .Bold = wdToggle .NameAscii = "宋体" .NameFarEast = "宋体" .NameBi = "宋体" .Size = 10 .SizeBi = 10 .Underline = 0 .Color = wdColorBlack End With Selection.TypeText Text:=.Fields("cpub") & Chr(32) & Chr(32) & .Fields
("date") & Chr(32) & Chr(32) & .Fields("page")
mydoc2.Bookmarks("cir").Select With Selection.Font .Bold = wdToggle .Name = "Arial" .Size = 10 End With If .Fields("net") = False Then Selection.TypeText Text:=.Fields("cir") & Chr(32) & Chr(32) & .Fields
("loc") Else Selection.TypeText Text:="N/A" End If
mydoc2.Bookmarks("size").Select With Selection.Font .Bold = wdToggle .Name = "Arial" .Size = 10 End With If .Fields("net") = False Then Selection.TypeText Text:=.Fields("size") Else Selection.TypeText Text:="N/A" End If
mydoc2.Bookmarks("author").Select With Selection.Font .Bold = wdToggle .Name = "Arial" .Size = 10 End With Selection.TypeText Text:=.Fields("author")
mydoc2.Bookmarks("cs").Select With Selection.Font .NameAscii = "宋体" .NameFarEast = "宋体" .NameBi = "宋体" .Size = 10 .SizeBi = 10 .Underline = 0 .Color = wdColorBlack End With Selection.TypeText Text:=.Fields("csummary")
mydoc2.Bookmarks("es").Select With Selection.Font .Name = "Arial" .Size = 10 End With Selection.TypeText Text:=.Fields("esummary") & Chr(13) & Chr(13)
mydoc2.Bookmarks("text").Select With Selection.Font .NameAscii = "宋体" .NameFarEast = "宋体" .NameBi = "宋体" .Size = 10 .SizeBi = 10 .Underline = 0 .Color = wdColorBlack End With Selection.TypeText Text:=.Fields("text") End With
For Each i In ActiveDocument.Bookmarks i.Delete Next If m < nrecord Then Selection.InsertBreak Type:=wdPageBreak mydoc1.Activate Selection.Copy mydoc2.Activate Selection.Paste End If Next m End Sub
这是我写的一个从access读取数据到word的代码,上面的是可以运行的,但是我将黑体部分改为下面的代码,就不能通过,提示“next 没有 for”,指向倒数第二行的“next m”。
mydoc2.Bookmarks("text").Select If .Fields("net") = True Then With Selection.Font .NameAscii = "宋体" .NameFarEast = "宋体" .NameBi = "宋体" .Size = 10 .SizeBi = 10 .Underline = 0 .Color = wdColorBlack End With Selection.TypeText Text:=.Fields("text") Else Selection.InlineShapes.AddPicture FileName:=.Fields("text"), LinkToFile:=False, SaveWithDocument:=True End If
那段插入图片的代码是我用录制宏得到的,问题是不是出在这里呢?
|