新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > Asp.net教程 > 正文:从Excel 单元格定位到Word 文档中指定的位置带来的思考

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

新客网 XKER.COM 2005-05-13 来源: 收藏本文

'以下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

收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐