I have created two new Word Documents through Excel vba, which was not yet saved. The documents were created as "Document1" and "Document2". When I try to switch between documents, I get Bad File name error 4160 for Document2. Please help me in resolving this issue.
Sub DocSwitch()
Dim s As Object
Set s = Word.Application.Selection
Documents("Document1").Select
s.TypeText Text:="Hello"
Documents("Document2").Select
s.TypeText Text:="Hi"
End Sub
Set s = Word.Application.Selection- once you do this,spoints at whatever was selected when that line ran, and doesn't dynamically update when you select something else. You'll need to repeat the line if you activate a different document. - Tim Williams