ShellExecute hangs Excel when opening XLS file
Jon Peltier wrote:
Check if it's an .xls file first, and if so, use Workbooks.Open to open it.
If not, go to shell.
- Jon
Thanks Jon,
Yes - it seems to be the easiest (only?) solution. I have slimmed the
code to the following:
' START QUOTE
Sub OpenDoc(DocCol As Integer)
Dim Filename As String
Dim Scr_hDC As Long
DocCol = DocCol + 2
With ThisWorkbook.Sheets("Documentation") ' Hidden sheet containing
dynamic list of filenames
Filename = .Cells(4, DocCol).Value
End With
If UCase(Right(Filename, 3)) = "XLS" Then
Workbooks.Open Filename:=Filename
Else
Scr_hDC = GetDesktopWindow()
ShellExecute Scr_hDC, "Open", Filename, "", "C:\", SW_SHOWNORMAL
End If
End Sub
' END QUOTE
One other question, though - is there any way to background the
ShellExecute events so that the rest of my code continues executing
while another programme (i.e. MS Word) is waiting for a user to respond
to a dialog box? There are a lot of Macro security warnings in some of
these documents, and if a user absent-mindedly opens a document and
forgets to deal with the security warning, code execution on the
spreadsheet will stop until they get around to it.
I know Excel is essentially a single-threading entity, but does that
apply to API calls as well?
Best regards,
Tristan
PS: Not the first time you've helped me and my company out, Jon - I
taught myself the fundaments of Office automation from your site, for
which thanks!)
|