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

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航