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

发表于:2007-06-30来源:作者:点击数: 标签:
@#以下 VB A脚本实现标题阐述功能,考虑以下问题: 如何捕获一个Cell单元格的单击事件?Excel 中能否添加处理其他的 Windows 消息? @#Unit : mcc @#Fun : Goto exactly position in Word from Excel impls by VBA. @#args : Bookmark string(predefined in

@#以下VBA脚本实现标题阐述功能,考虑以下问题:
如何捕获一个Cell单元格的单击事件?Excel 中能否添加处理其他的Windows 消息?
@#Unit   :   mclearcase/" target="_blank" >cc
@#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

原文转自:http://www.ltesting.net