Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,665
- Office Version
- 365
- 2016
- Platform
- Windows
I hope someone is able to help me correct a problem with my VBA code.
This is what I wished this code would do ...
When mi5 = "GE", then open all the Word documents in directory path_name that end with "-GE.docx". For my testing, there are 2 of 13 files that end in "-GE.docx".
What is happening is that my Excel project locks up with the code waiting to complete complete an OLE action. ("Microsoft Excel is waiting for another application to complete an OLE action."). The only way I can recover is to end a task in task manager called "File In Use". Doing so returns me to Excel with an error "Command Failed" with the line highlighted in red.
I'm not all that certain I know how this code works, so I assume I have some things missing and/or out of order. I hope someone is able to help me clean up my code to produce the desired results I seek ... the two reports printed.
Rich (BB code):
...
ElseIf mi5 = "GE" Then
StrFile = Dir(path_name & "*-GE.docx")
Do While Len(StrFile) > 0
Debug.Print StrFile
Set WordApp = CreateObject("word.Application")
WordApp.documents.Open path_name & StrFile
WordApp.Visible = True
Set WordApp = Nothing
StrFile = Dir
Loop
WordApp.Activate
Exit Sub
Else
....
End if
This is what I wished this code would do ...
When mi5 = "GE", then open all the Word documents in directory path_name that end with "-GE.docx". For my testing, there are 2 of 13 files that end in "-GE.docx".
What is happening is that my Excel project locks up with the code waiting to complete complete an OLE action. ("Microsoft Excel is waiting for another application to complete an OLE action."). The only way I can recover is to end a task in task manager called "File In Use". Doing so returns me to Excel with an error "Command Failed" with the line highlighted in red.
I'm not all that certain I know how this code works, so I assume I have some things missing and/or out of order. I hope someone is able to help me clean up my code to produce the desired results I seek ... the two reports printed.