Home
TeamSite
Open Word document at bookmark
StevenD
Hello,
I currently open documents from Worksite via something that looks like a hyperlink that actually calls a VB6 app.
The link will successfully open a document natively, such as Microsoft Word, however I am now investigating whether I can pass something to open a Word document at a particular bookmark.
Here is a snippet of the code that successfully opens a document at the moment, just to demonstrate what classes and methods I am currently using. (I have left out other irrelevant code.)
------------------------------------------------
Private m_objDatabase As IManage.NRTDatabase
Dim p_objNRTDoc As IManage.NRTDocument
Dim p_objSelectedNRTDocuments() As IManage.NRTDocument
ReDim p_objSelectedNRTDocuments(0)
'set session and database etc etc here...(not shown)
'get document
Set p_objNRTDoc = m_objDatabase.GetDocument("99999999", 1)
Set p_objSelectedNRTDocuments(0) = p_objNRTDoc
' Open Command
Set p_objOpenCmd = New IMANEXTLib.OpenCmd
Set p_objContextItems = New IMANEXTLib.ContextItems
p_objOpenCmd.Initialize p_objContextItems
p_objContextItems.Add "SelectedNRTDocuments", p_objSelectedNRTDocuments
p_objOpenCmd.Update
p_objOpenCmd.Execute
------------------------------------------------
I'm guessing this is the key line:
Set p_objNRTDoc = m_objDatabase.GetDocument("99999999", 1)
Just not sure if it is possible - anyone solved this before?
Find more posts tagged with
Comments
Migrateduser
Hi Steven, not sure about my answer but I don't think you could add to your code the possibility of opening at a particular boobkmark, unless you create a template (dot file) with a macro which maybe you can call from your code.
Not sure if you can call from your code to a macro...probably yes, what I'm sure is that you will need a dot file in the startup folder (or save this macro in normal.dot which is not very safety because users could delete it). This dot in startup will be loaded when word opens and you will have a macro visible from your enviroment, if you can run this macro from your code...you will go to the bookmark handling the opening proccess.
As told you, not sure if this is available...only an idea to help, sure there is an easier way..
Hope it helps
Javi
StevenD
Hi Javi,
Thanks for the fast reply. I think you are right in some respects, in that there appears to be nothing in the SDK that will automatically allow me to open a MS Word document natively passing appropriate commands to navigate straight to a bookmark.
What I''l try is exporting the file locally then opening the file natively 'outside' of any SDK commands (like some command-line method) which will allow me to pass the bookmark parameter that MS Word will understand.
If I find the answer, I'll post it here. Or if someone already knows how to open a MS Word document at a specified bookmark through something like a command line, then please post it here!
Kind Regards.
StevenD
OK here is my solution. Export the document locally out of Worksite and use Word Automation to open the local file with the bookmark name. Then record history in Worksite.
'build export path
p_strExportPath = Environ("UserProfile") & "\Local Settings\Temp\NetRight\" & p_objNRTDoc.Database.Name & "_" & p_objNRTDoc.Number & "_" & p_objNRTDoc.Version & "." & p_objNRTDoc.Extension
'copy document locally
p_objNRTDoc.GetCopy p_strExportPath, GetCopyOptions.nrNativeFormat
'open file natively at bookmark
Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
Set objWordApp = CreateObject("Word.Application")
Set objWordDoc = objWordApp.Documents.Open(strFileName)
objWordApp.Visible = True
objWordDoc.Bookmarks(strBookmark).Select
Set objWordDoc = Nothing
Set objWordApp = Nothing
'update history log in Worksite
p_objNRTDoc.HistoryList.Add nrHistoryExport, 0, 0, UCase(App.EXEName), , UCase(Environ("ComputerName"))