Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a file in the same instance with ShellExecute
Hi everyone,
If someone knows if it's possible to use "ShellExecute" (not workbooks.open) to open a file in the same instance of the application where the macro is ? If yes, How to do it ? 'API Private Declare Function ShellExecute Lib "shell32.dll" Alias _ "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _ String, ByVal lpszFile As String, ByVal lpszParams As String, _ ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '----------------------------------------- Sub ShellOpenFile() Const SW_SHOWNORMAL = 1 Dim hwnd As Long Dim File As String File = "C:\Workbook2.xls" hwnd = FindWindow(vbNullString, Application.Caption) ShellExecute hwnd, "open", File, vbNullString, vbNullString, SW_SHOWDEFAULT End Sub '----------------------------------------- Thanks for your collaboration and your help. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a file in the same instance with ShellExecute
Try sending the desktop window 0
ShellExecute 0&, "open", Chr(34) & File & Chr(34), _ vbNullString, vbNullString, vbNormalFocus May be worth bracketing the file with quotes in case of spaces as above. If multiple excel instances are open ensure yours is the active window, doesn't guarantee it won't open in an arbitrary instance but it seems to help. But surely, why not simply use workbooks.open. Regards, Peter T "MichDenis" wrote in message ... Hi everyone, If someone knows if it's possible to use "ShellExecute" (not workbooks.open) to open a file in the same instance of the application where the macro is ? If yes, How to do it ? 'API Private Declare Function ShellExecute Lib "shell32.dll" Alias _ "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _ String, ByVal lpszFile As String, ByVal lpszParams As String, _ ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '----------------------------------------- Sub ShellOpenFile() Const SW_SHOWNORMAL = 1 Dim hwnd As Long Dim File As String File = "C:\Workbook2.xls" hwnd = FindWindow(vbNullString, Application.Caption) ShellExecute hwnd, "open", File, vbNullString, vbNullString, SW_SHOWDEFAULT End Sub '----------------------------------------- Thanks for your collaboration and your help. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a file in the same instance with ShellExecute
Thanks for your response.... but it's not working !
My goal was to be able to open a .DQY file using a vba procedure. The submitted "sub" do the job but open the desired file in another instance of Excel. If someone knows a way of doing it within tne same instance, I will be pleased to know it. Thanks for your collaboration. 'API Private Declare Function ShellExecute Lib "shell32.dll" Alias _ "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _ String, ByVal lpszFile As String, ByVal lpszParams As String, _ ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '----------------------------------------- Sub ShellOpenFile() Const SW_SHOWNORMAL = 1 Dim hwnd As Long Dim File As String File = "C:\Workbook2.xls" hwnd = FindWindow(vbNullString, Application.Caption) ShellExecute hwnd, "open", File, vbNullString, vbNullString, SW_SHOWDEFAULT End Sub '----------------------------------------- |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Open new instance of excel every time I click file | Excel Discussion (Misc queries) | |||
How to open a new instance of EXCEL and .xls file | Excel Worksheet Functions | |||
How to open a new instance of Word and its .doc file | Excel Worksheet Functions | |||
ShellExecute hangs Excel when opening XLS file | Excel Programming | |||
I would like to open a new instance of Excel each time I double-click on a xls file | Excel Worksheet Functions |