Office中国论坛/Access中国论坛

标题: 请教如何向WORD传送备注类型的数据?!(已解决,谢谢各位) [打印本页]

作者: sxgaobo    时间: 2010-7-11 11:59
标题: 请教如何向WORD传送备注类型的数据?!(已解决,谢谢各位)
本帖最后由 sxgaobo 于 2010-7-11 20:50 编辑

这样只能传送255个字符,怎样能改为备注型的啊?我需要传递更多的字符.
我把代码传上来,方便各位查看
    On Error Resume Next
    Dim docApp As Object
    Set docApp = GetObject(, "Word.Application")
   
    If Err Then
        Err.Clear
        Set docApp = CreateObject("Word.Application")
        
        If Err Then
            MsgBox "操作中没有装WORD程序!", vbQuestion, "系统提示"
            Exit Sub
        End If
    End If
    docApp.Visible = False
    Dim Doc As Object
    Dim win As Object
        Set Doc = docApp.Documents.Add(CurrentProject.Path & "\一般处罚.doc")
        Set win = Doc.ActiveWindow

        win.View.SeekView = wdSeekPrimaryHeader
        With win.Selection.Find
        
            .Text = "[内容]"
            .Replacement.Text = [1]
            .Execute , , , , , , , , , , 2
        End With
     docApp.Visible = True

作者: admin    时间: 2010-7-11 14:46
这个限制是由宏的255限制的。有人使用
要设置的栏位设置个标签
doc.Bookmarks("标签“).Range.Text = (rs!字段名)

作者: admin    时间: 2010-7-11 14:48
引用 ningyong网友的方法:

word模版套打有几种方法.
方法一
'直接把数据写道Word模板,从文档头依次往下排
'   好处:简单易懂,可把大数据写入到Word模板里
'   缺点:不能把数据写入到Word模板相应的位置
方法二
'替换Word上的相应文本标记“[template_name]”,“[template_content_en]”
'   好处:该方法易于以后的项目维护,数据来是哪,替换那个一目了然。
'   缺点:如果数据量多于255个字符,不能替换
方法三
'使用Word标签(BookMark)
'   好处:不管数据有多大,都能完全写道Word模板相应位置
'   缺点:标签不易于维护

作者: admin    时间: 2010-7-11 14:49
方法一
'直接把数据写道Word模板,从文档头依次往下排
'   好处:简单易懂,可把大数据写入到Word模板里
'   缺点:不能把数据写入到Word模板相应的位置

        With win   '使用查找和替换
            .Selection.typetext (rs!template_name)
            .Selection.Typeparagraph           '换行
            .Selection.typetext (rs!template_content_en)
       End With
作者: admin    时间: 2010-7-11 14:49
方法二(ningyong)
'替换Word上的相应文本标记“[template_name]”,“[template_content_en]”
'   好处:该方法易于以后的项目维护,数据来是哪,替换那个一目了然。
'   缺点:如果数据量多于255个字符,不能替换

     With win.Selection.Find   '使用查找和替换
        .Text = "[template_name]"
        .Replacement.Text = Nz(rs!template_name, "")
        .Execute , , , , , , , , , , 2

        .Text = "[template_content_en]"
        .Replacement.Text = Nz(rs!template_content_en, "")
        .Execute , , , , , , , , , , 2
     End With
作者: admin    时间: 2010-7-11 14:50
方法三(ningyong)
'使用Word标签(BookMark)
'   好处:不管数据有多大,都能完全写道Word模板相应位置
'   缺点:标签不易于维护
        doc.Bookmarks("template_name").Range.Text = (rs!template_name)
        doc.Bookmarks("template_content_en").Range.Text = (rs!template_content_en)
   
    doc.PrintPreview    '打印预览
    'doc.PrintOut        '直接打印
    Next
    docApp.Visible = True   '自动化完成后,显示WORD程序


Exit_save_Click:
    Exit Sub

Err_save_Click:
    MsgBox Err.Description
    Resume Exit_save_Click

End Sub
作者: sxgaobo    时间: 2010-7-11 16:02
本帖最后由 sxgaobo 于 2010-7-11 16:35 编辑

谢谢您的关注,您能帮我把我发的那段代码改成第3种方法吗?
或者告诉我怎么做,我不太懂代码,不好意思啊!
我没理解错的话,是应该先在WORW模版中建立标签,哪位朋友能告诉我怎么建立标签啊?!
先谢了!!!

作者: 路遥    时间: 2010-12-23 22:56
关注,最好搞个实例





欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3