首页 > 开发 > 综合 > 正文

从Excel 单元格定位到Word 文档中指定的位置带来的思考

2024-07-21 02:25:02
字体:
来源:转载
供稿:网友


'以下vba脚本实现标题阐述功能,考虑以下问题:
如何捕获一个cell单元格的单击事件?excel 中能否添加处理其他的windows 消息?
'unit   :   mcc
'fun    :   goto exactly position in word from excel impls by vba.
'args   :   bookmark string(predefined in word handed yourself or using tools)
'ref    :   ms word/excel object lib.
'modify :   1.open word archives in readonly way 2.get abs path using for anchor
'future :   1.search by string exactly
'author :   qjwxsd
'dt     :   2005-04-18~~

const tc3 = "tc03_軟体版權管理/tc03_software license management"
const tc4 = "tc04_配備資源管理/tc04_periphery resource"
const tc10 = "tc10_資料安全管理/tc10_data security management"

public sub gotoword(filename, bookmark as string)
    on error resume next
    dim a as word.application
    dim b as word.document
   
    dim c as excel.application
    dim d as excel.workbook
    dim e as excel.worksheet

    dim path as string
   
    set c = getobject(, "excel.application")
    set d = c.activeworkbook
    set e = d.activesheet
    'path = c.path
    path = d.path
    '取得当前功能清单的路径,传到word中。否则word无法取得路径,
    '打开相应的tc。
    set a = getobject(, "word.application")
    if a = null then
        set a = createobject("word.application")
    end if
   
    'a.documents.open "h:/0408/pcmain5.5.0 _other.doc"
    'msgbox a.path
    'msgbox application.path
    'msgbox curdir
    'msgbox a.documents.item(0).fullname
   
    a.documents.open path & "/" & filename & ".doc", readonly:=true
    a.selection.goto what:=wdgotobookmark, name:=bookmark
    a.visible = true
    a.activate '前台显示word窗体
end sub

private sub label1_click()
    gotoword tc3, "tc3_1"
end sub

private sub label10_click()
    gotoword tc4, "tc4_4"
end sub

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表