![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've got (among other things) an Excel and a Word button on a ribbon bar. They each call the following code which works as intended, but Excel opens on top of my application (which is Maximised), while the Word document opens on the task bar only. How can I get them both to open the same way? Dim objOffice As Object Dim strApp As String Select Case vAppType Case 1: strApp = "Excel" Case 2: strApp = "Word" End Select If Not IsAppRunning(strApp) Then Set objOffice = CreateObject(strApp & ".Application") Else Set objOffice = GetObject(, strApp & ".Application") End If objOffice.Application.Visible = True Select Case vAppType Case 1: objOffice.Workbooks.Add Case 2: objOffice.Documents.Add objOffice.Documents(1).Activate objOffice.Application.WindowState = 0 ' wdWindowStateNormal End Select |
#3
| |||
| |||
|
|
I've got (among other things) an Excel and a Word button on a ribbon bar. They each call the following code which works as intended, but Excel opens on top of my application (which is Maximised), while the Word document opens on the task bar only. How can I get them both to open the same way? Dim objOffice As Object Dim strApp As String Select Case vAppType Case 1: strApp = "Excel" Case 2: strApp = "Word" End Select If Not IsAppRunning(strApp) Then Set objOffice = CreateObject(strApp & ".Application") Else Set objOffice = GetObject(, strApp & ".Application") End If objOffice.Application.Visible = True Select Case vAppType Case 1: objOffice.Workbooks.Add Case 2: objOffice.Documents.Add objOffice.Documents(1).Activate objOffice.Application.WindowState = 0 ' wdWindowStateNormal End Select -- Bob Darlington Brisbane |
#4
| |||
| |||
|
|
I've got (among other things) an Excel and a Word button on a ribbon bar. They each call the following code which works as intended, but Excel opens on top of my application (which is Maximised), while the Word document opens on the task bar only. How can I get them both to open the same way? Dim objOffice As Object Dim strApp As String Select Case vAppType Case 1: strApp = "Excel" Case 2: strApp = "Word" End Select If Not IsAppRunning(strApp) Then Set objOffice = CreateObject(strApp & ".Application") Else Set objOffice = GetObject(, strApp & ".Application") End If objOffice.Application.Visible = True Select Case vAppType Case 1: objOffice.Workbooks.Add Case 2: objOffice.Documents.Add objOffice.Documents(1).Activate objOffice.Application.WindowState = 0 ' wdWindowStateNormal End Select -- Bob Darlington Brisbane |
#5
| |||
| |||
|
|
On 11/11/2011 07:22:56, "Bob Darlington" wrote: I've got (among other things) an Excel and a Word button on a ribbon bar. They each call the following code which works as intended, but Excel opens on top of my application (which is Maximised), while the Word document opens on the task bar only. How can I get them both to open the same way? Dim objOffice As Object Dim strApp As String Select Case vAppType Case 1: strApp = "Excel" Case 2: strApp = "Word" End Select If Not IsAppRunning(strApp) Then Set objOffice = CreateObject(strApp & ".Application") Else Set objOffice = GetObject(, strApp & ".Application") End If objOffice.Application.Visible = True Select Case vAppType Case 1: objOffice.Workbooks.Add Case 2: objOffice.Documents.Add objOffice.Documents(1).Activate objOffice.Application.WindowState = 0 ' wdWindowStateNormal End Select This may give you a start (or not) Private Declare Function apiGetDesktopWindow Lib "user32" Alias _ "GetDesktopWindow" () As Long Private Declare PtrSafe Function GetWindow Lib "user32" _ (ByVal hwnd As Long, ByVal wCmd As Long) As Long Private vate Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function apiGetClassName Lib "user32" Alias _ "GetClassNameA" (ByVal hwnd As Long, _ ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Function fEnumWindows() Dim lngX As Long Dim lngStyle As Long, strCaption As String Dim ThisDBCaption As String Dim ThisDbHwnd As Long Dim Msg As String lngX = apiGetDesktopWindow() 'Return the first child to Desktop lngX = apiGetWindow(lngX, mcGWCHILD) Do While Not lngX = 0 strCaption = fGetCaption(lngX) If Len(strCaption) > 0 Then Debug.Print strCaption lngStyle = apiGetWindowLong(lngX, mcGWLSTYLE) 'enum visible windows only If fGetClassName(lngX) = "OMain" Then ' Databases If lngStyle And mcWSVISIBLE Then If ThisDBCaption = "" Then ThisDBCaption = fGetCaption(lngX) ThisDbHwnd = lngX Else If ThisDBCaption = fGetCaption(lngX) Then Msg Msg = "Do you want 2 copies of " & ThisDBCaption & " running?" If If MsgBox(Msg, vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then Call fSetAccessWindow(SW_SHOWMAXIMIZED) Application.Quit Else Exit Function End If End If End If GoTo NextWindow End If End If End If NextWindow: lngX = apiGetWindow(lngX, mcGWHWNDNEXT) Loop End Function Private Function fGetClassName(hwnd As Long) As String Dim strBuffer As String Dim intCount As Integer strBuffer = String$(mconMAXLEN - 1, 0) intCount = apiGetClassName(hwnd, strBuffer, mconMAXLEN) If intCount > 0 Then fGetClassName = Left$(strBuffer, intCount) End If End Function |
#6
| |||
| |||
|
|
Phil. I'm still trying to muddle through this one. Did you have the code for fGetCaption() ? |
#7
| |||
| |||
|
| Phil. I'm still trying to muddle through this one. Did you have the code for fGetCaption() ? Hi Bob Private Declare Function apiGetWindowText Lib "user32" Alias _ "GetWindowTextA" (ByVal hwnd As Long, ByVal _ lpString As String, ByVal aint As Long) As Long Private Function fGetCaption(hwnd As Long) As String Dim strBuffer As String Dim intCount As Integer strBuffer = String$(mconMAXLEN - 1, 0) intCount = apiGetWindowText(hwnd, strBuffer, mconMAXLEN) If intCount > 0 Then fGetCaption = Left$(strBuffer, intCount) End If End Function Phil |
#8
| |||
| |||
|
|
I've got (among other things) an Excel and a Word button on a ribbon bar. They each call the following code which works as intended, but Excel opens on top of my application (which is Maximised), while the Word document opens on the task bar only. How can I get them both to open the same way? Dim objOffice As Object Dim strApp As String Select Case vAppType Case 1: strApp = "Excel" Case 2: strApp = "Word" End Select If Not IsAppRunning(strApp) Then Set objOffice = CreateObject(strApp& ".Application") Else Set objOffice = GetObject(, strApp& ".Application") End If objOffice.Application.Visible = True Select Case vAppType Case 1: objOffice.Workbooks.Add Case 2: objOffice.Documents.Add objOffice.Documents(1).Activate objOffice.Application.WindowState = 0 ' wdWindowStateNormal End Select |
![]() |
| Thread Tools | |
| Display Modes | |
| |