U
Umpty
Summary: I am working from within MS Access. I open "DocumentA", read a
column of values (one at a time). For each read, I go to "DocumentB" and
walk down a column of values to see if that value is equal to the value that
was read from "DocumentA". If it is, it sets a hyperlink, referencing a
bookmark in "DocumentA".
Problem is: It does this fine on the first iteration but when it goes back
to the code for "DocumentA", the active document focus is on "Document B" and
I need to get the focus back on "Document A". I have tried to use code such
as:
Documents.("DocumentB.doc").Activate but that does not work. I get an
error that says "Bad file name".
Any help in reseting the focus back on "DocumentB.doc" would be greatly
appreciated.
' This code opens "DocumentA.doc" and does what it needs (only on the first
iteration).
Dim TotRows As Integer
Set oApp = New Word.Application
oApp.Documents.Open CurrentProject.Path & "\DocumentB.doc"
oApp.Visible = True
TotRows = oApp.ActiveDocument.Tables(strTableID).Rows.Count
Dim i As Integer
For i = 1 To TotRows
Dim TotLen As Integer, MyText As String, MyBkmrk As String
oApp.ActiveDocument.Tables(strTableID).Rows(i).Cells(2).Select
TotLen = Len(oApp.Selection.Text) - 2
MyText = Trim(Left(oApp.Selection.Range, TotLen))
MyBkmrk = strBkMrkPrefix & i
OpenPicklistFile strTableID, MyText, MyBkmrk
Next i
'This code opens Document B and does it's thing and goes back to previous
code to do the next read.
oApp.Documents.Open CurrentProject.Path & "\DocumentB.doc"
oApp.Visible = True
TotTables = oApp.ActiveDocument.Tables.Count
For j = 1 To TotTables
TotRows = oApp.ActiveDocument.Tables(j).Rows.Count
For i = 3 To TotRows
oApp.ActiveDocument.Tables(j).Rows(i).Cells(MyColumnNum).Range.Select
TotLen = Len(oApp.Selection.Text) - 2
myValue = Trim(Left(oApp.Selection.Range, TotLen))
If myValue = strMyText Then
oApp.Selection.Range.Delete
oApp.ActiveDocument.Hyperlinks.Add
Anchor:=oApp.Selection.Range, Address:= _
"DocumentA.doc", SubAddress:=strBkMrk, _
ScreenTip:="", TextToDisplay:=myValue
End If
Next i
Next j
column of values (one at a time). For each read, I go to "DocumentB" and
walk down a column of values to see if that value is equal to the value that
was read from "DocumentA". If it is, it sets a hyperlink, referencing a
bookmark in "DocumentA".
Problem is: It does this fine on the first iteration but when it goes back
to the code for "DocumentA", the active document focus is on "Document B" and
I need to get the focus back on "Document A". I have tried to use code such
as:
Documents.("DocumentB.doc").Activate but that does not work. I get an
error that says "Bad file name".
Any help in reseting the focus back on "DocumentB.doc" would be greatly
appreciated.
' This code opens "DocumentA.doc" and does what it needs (only on the first
iteration).
Dim TotRows As Integer
Set oApp = New Word.Application
oApp.Documents.Open CurrentProject.Path & "\DocumentB.doc"
oApp.Visible = True
TotRows = oApp.ActiveDocument.Tables(strTableID).Rows.Count
Dim i As Integer
For i = 1 To TotRows
Dim TotLen As Integer, MyText As String, MyBkmrk As String
oApp.ActiveDocument.Tables(strTableID).Rows(i).Cells(2).Select
TotLen = Len(oApp.Selection.Text) - 2
MyText = Trim(Left(oApp.Selection.Range, TotLen))
MyBkmrk = strBkMrkPrefix & i
OpenPicklistFile strTableID, MyText, MyBkmrk
Next i
'This code opens Document B and does it's thing and goes back to previous
code to do the next read.
oApp.Documents.Open CurrentProject.Path & "\DocumentB.doc"
oApp.Visible = True
TotTables = oApp.ActiveDocument.Tables.Count
For j = 1 To TotTables
TotRows = oApp.ActiveDocument.Tables(j).Rows.Count
For i = 3 To TotRows
oApp.ActiveDocument.Tables(j).Rows(i).Cells(MyColumnNum).Range.Select
TotLen = Len(oApp.Selection.Text) - 2
myValue = Trim(Left(oApp.Selection.Range, TotLen))
If myValue = strMyText Then
oApp.Selection.Range.Delete
oApp.ActiveDocument.Hyperlinks.Add
Anchor:=oApp.Selection.Range, Address:= _
"DocumentA.doc", SubAddress:=strBkMrk, _
ScreenTip:="", TextToDisplay:=myValue
End If
Next i
Next j