Sub ListOpenWordDocs()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim strDocs As String
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
MsgBox "No active instance of MS Word"
Exit Sub
End If
On Error GoTo 0
For Each objDoc In objWord.Documents
strDocs = strDocs & objDoc.Name & vbCrLf
Next
MsgBox strDocs
End Sub
Code:Sub ListOpenWordDocs() Dim objWord As Word.Application Dim objDoc As Word.Document Dim strDocs As String On Error Resume Next Set objWord = GetObject(, "Word.Application") If Err.Number <> 0 Then MsgBox "No active instance of MS Word" Exit Sub End If On Error GoTo 0 For Each objDoc In objWord.Documents strDocs = strDocs & objDoc.Name & vbCrLf Next MsgBox strDocs End Sub
Sub ListOpenWordDocs()
Dim objWord As Word.Application
Dim objDoc As Word.Document
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
MsgBox "No active instance of MS Word"
Exit Sub
End If
On Error GoTo 0
For Each objDoc In objWord.Documents
If objDoc.Name = "Document1" Then
Exit For
End If
Next
If objDoc Is Nothing Then
Exit Sub
End If
'objDoc should now be a reference to "Document1" and it can be modified
objDoc.Range.Select
With objWord.Selection
.EndKey wdStory 'move the insertion point to the end of the document
.TypeParagraph
.TypeParagraph
.TypeText "hello"
End With
End Sub
objWord is a reference to the Word application. objWord.Documents is the array of current documents.
Take a look at the code below which looks for an open document named "Document1" and inserts the word "hello" at the end.
Code:Sub ListOpenWordDocs() Dim objWord As Word.Application Dim objDoc As Word.Document On Error Resume Next Set objWord = GetObject(, "Word.Application") If Err.Number <> 0 Then MsgBox "No active instance of MS Word" Exit Sub End If On Error GoTo 0 For Each objDoc In objWord.Documents If objDoc.Name = "Document1" Then Exit For End If Next If objDoc Is Nothing Then Exit Sub End If 'objDoc should now be a reference to "Document1" and it can be modified objDoc.Range.Select With objWord.Selection .EndKey wdStory 'move the insertion point to the end of the document .TypeParagraph .TypeParagraph .TypeText "hello" End With End Sub
Dim objTable as Word.Table 'to declare the object
for each objTable in objDoc.tables
'do stuff
next
It's probably the cell marker, which is a circle with four lines on the corners (yeah I know circle with corners!!!).
When getting the string just do:
myStr=left(myStr,len(myStr)-1)
to get rid of it