lynnnow
12-22-2006, 04:11 AM
Hi,
I've got a list of Word documents that I need to open and work with. Since this list is pretty long and the files have a particular order to be done, I have made a chronological list and I open the files from Excel itself. So far I have to CreateObject and the file is opened in a new instance of Word. My objective is to open the Word documents in the current instance instead of closing and opening Word all the time. The reason I am doing this is because the number of files is huge and it is easy just opening the file(s) from Excel itself.
So far this is what I have managed to do:
Sub DocOpen()
Dim wdNew As Object
Dim File2Open As String
With Application.FileSearch
.LookIn = "D:\Lincoln\Today's Work\" & Format(ActiveCell.Offset(0, -1).Value, "mmmm dd")
.FileName = ActiveCell.Value & "-"
.FileType = msoFileTypeWordDocuments
.Execute
If .FoundFiles.Count <> 0 Then
Set wdnew = CreateObject("Word.Application")
wdnew.Visible = True
i = 1
Do While i <= .FoundFiles.Count
File2Open = .LookIn & "\" & .FileName & i '& ".doc"
On Error Resume Next
wdnew.documents.Open File2Open
i = i + 1
Loop
Else
MsgBox "No files of this name could be found", vbExclamation, "...::: Lynx's Corner :::..."
End If
End With
End Sub
This works fine for me right now, the only problem is opening and closing the instance of Word every time and letting Excel start a new instance instead of opening the Word document in the current instance.
Any help/pointers in the right direction is appreciated.
Thanks,
Lincoln
I've got a list of Word documents that I need to open and work with. Since this list is pretty long and the files have a particular order to be done, I have made a chronological list and I open the files from Excel itself. So far I have to CreateObject and the file is opened in a new instance of Word. My objective is to open the Word documents in the current instance instead of closing and opening Word all the time. The reason I am doing this is because the number of files is huge and it is easy just opening the file(s) from Excel itself.
So far this is what I have managed to do:
Sub DocOpen()
Dim wdNew As Object
Dim File2Open As String
With Application.FileSearch
.LookIn = "D:\Lincoln\Today's Work\" & Format(ActiveCell.Offset(0, -1).Value, "mmmm dd")
.FileName = ActiveCell.Value & "-"
.FileType = msoFileTypeWordDocuments
.Execute
If .FoundFiles.Count <> 0 Then
Set wdnew = CreateObject("Word.Application")
wdnew.Visible = True
i = 1
Do While i <= .FoundFiles.Count
File2Open = .LookIn & "\" & .FileName & i '& ".doc"
On Error Resume Next
wdnew.documents.Open File2Open
i = i + 1
Loop
Else
MsgBox "No files of this name could be found", vbExclamation, "...::: Lynx's Corner :::..."
End If
End With
End Sub
This works fine for me right now, the only problem is opening and closing the instance of Word every time and letting Excel start a new instance instead of opening the Word document in the current instance.
Any help/pointers in the right direction is appreciated.
Thanks,
Lincoln