muttleee
12-06-2005, 04:33 AM
Hiyas,
I am trying to read information from a pre-existing Word document and populate a Lotus Notes form with it. This works ok so far in testing but the problem I have is that the Word document seems to lock after I read data from it. The Notes agent works when I run it but if I then try to open the Word document (on my desktop), Word briefly starts to open and then I get a message asking if I want to revert to the saved version of the document. It doesn't matter if I choose yes or no - it still refuses to open any further and I have to resort to Ctrl+Alt+Del to get rid of the instance of Word.
Here's the code in the Notes doc that is reading from the Word doc:
Sub Postopen(Source As Notesuidocument)
Dim session As New notessession
If Source.IsNewDoc Then
'open the appropriate Word doc from the desktop
Set wdapp = CreateObject("word.application")
wdapp.documents.Open ("C:\Documents and Settings\smithj\Desktop\PSA and Dept'l Targets.doc")
wdapp.Visible = False
Set wddoc=wdapp.activedocument
wddoc.tables(1).rows(2).cells(5).select 'select a particular cell
Dim strTemp As String
strTemp = wdapp.selection.Text 'read text from the selected cell
If Source.EditMode Then
Call Source.FieldSetText ( "DeptTarget", strTemp) 'set text in field if Notes doc is editable
Else
Msgbox "'Postopen set text didn't work" 'else display error message
End If
End If
Set wdApp = Nothing 'close Word doc
Set wddoc = Nothing
End Sub
I wouldn't have thought anything should stop me opening the Word doc even after reading from it programatically. If I try to run the agent again immediately after I have run it the first time, I get a message saying the doc is "locked for editing by ' ' " but it still works ok as long as I click 'Read Only'.
Is there any way I can get round this problem..? Thanks in advance for any suggestions. http://vbaexpress.com/forum/images/smilies/001.gif
I am trying to read information from a pre-existing Word document and populate a Lotus Notes form with it. This works ok so far in testing but the problem I have is that the Word document seems to lock after I read data from it. The Notes agent works when I run it but if I then try to open the Word document (on my desktop), Word briefly starts to open and then I get a message asking if I want to revert to the saved version of the document. It doesn't matter if I choose yes or no - it still refuses to open any further and I have to resort to Ctrl+Alt+Del to get rid of the instance of Word.
Here's the code in the Notes doc that is reading from the Word doc:
Sub Postopen(Source As Notesuidocument)
Dim session As New notessession
If Source.IsNewDoc Then
'open the appropriate Word doc from the desktop
Set wdapp = CreateObject("word.application")
wdapp.documents.Open ("C:\Documents and Settings\smithj\Desktop\PSA and Dept'l Targets.doc")
wdapp.Visible = False
Set wddoc=wdapp.activedocument
wddoc.tables(1).rows(2).cells(5).select 'select a particular cell
Dim strTemp As String
strTemp = wdapp.selection.Text 'read text from the selected cell
If Source.EditMode Then
Call Source.FieldSetText ( "DeptTarget", strTemp) 'set text in field if Notes doc is editable
Else
Msgbox "'Postopen set text didn't work" 'else display error message
End If
End If
Set wdApp = Nothing 'close Word doc
Set wddoc = Nothing
End Sub
I wouldn't have thought anything should stop me opening the Word doc even after reading from it programatically. If I try to run the agent again immediately after I have run it the first time, I get a message saying the doc is "locked for editing by ' ' " but it still works ok as long as I click 'Read Only'.
Is there any way I can get round this problem..? Thanks in advance for any suggestions. http://vbaexpress.com/forum/images/smilies/001.gif