I am new to VBA and I hope I have posted this in the right forum.
I am trying to copy text from one opened Word document to another using a macro. In the macro I check to see if the source document is opened then move the data at each specified bookmark to another specified bookmark in the destination document.
When I first ran this code it 'worked' like a charm. Now I keep getting the spurious message saying "5941"
Can anyone help me?
__________________________________________________________
Private Sub Document_Open()
Dim strDocName As String
strDocName = "U:\Work\LHN Assessment - MASTER.doc"
If DocOpen(strDocName) = True Then
Dim appWord As Word.Application
Dim SrcDoc As Word.Document
Dim DestDoc As Word.Document
Set DestDoc = ActiveDocument
Set SrcDoc = Documents.Open("U:\Work\LHN Assessment - MASTER.doc")
' Set appWord = CreateObject("Word.Application")
'Sex'
DestDoc.Bookmarks("Text473").Range.Text = SrcDoc.Bookmarks("Text318").Range.Text
DestDoc.Bookmarks("Text487").Range.Text = SrcDoc.Bookmarks("Chk103").Range.Text
Else
MsgBox "LHN Assessment Document is closed"
End If
End Sub
I am trying to copy text from one opened Word document to another using a macro. In the macro I check to see if the source document is opened then move the data at each specified bookmark to another specified bookmark in the destination document.
When I first ran this code it 'worked' like a charm. Now I keep getting the spurious message saying "5941"
Can anyone help me?
__________________________________________________________
Private Sub Document_Open()
Dim strDocName As String
strDocName = "U:\Work\LHN Assessment - MASTER.doc"
If DocOpen(strDocName) = True Then
Dim appWord As Word.Application
Dim SrcDoc As Word.Document
Dim DestDoc As Word.Document
Set DestDoc = ActiveDocument
Set SrcDoc = Documents.Open("U:\Work\LHN Assessment - MASTER.doc")
' Set appWord = CreateObject("Word.Application")
'Sex'
DestDoc.Bookmarks("Text473").Range.Text = SrcDoc.Bookmarks("Text318").Range.Text
DestDoc.Bookmarks("Text487").Range.Text = SrcDoc.Bookmarks("Chk103").Range.Text
Else
MsgBox "LHN Assessment Document is closed"
End If
End Sub