Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.access,microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default How to force an application to be visible?

I have a form in Access that calls a complex Excel VBA function to
generate a report, like this...

Public Sub RunReport()
On Error Resume Next
Set oExcelApp = GetObject(, "Excel.Application")
If Err < 0 Then
' excel wasn't running, start it from code
Set oExcelApp = CreateObject("Excel.Application")
End If
On Error GoTo 0

ret = oExcelApp.Application.Run("ReportCreate.xla!BuildR eport",
Me.ReportId)
End Sub

The code works fine, and a report is generated. The problem is that if
Excel was not running when it was called, it opens in the background
somewhere and never becomes visible. On some people's machines a new
instance of Excel is opened whether or not it was already running, so
they can never see the resulting reports.

MS has a command called "AppActivate" that apparently claims to be
able to bring the app forward, but I'm at a loss how to actually use
it:

AppActivate "Microsoft Excel"

results in "Run-time Error 5: Invalid procedure call or argument". The
documents SEEM to suggest this is because a window with that exact
name cannot be found, but if that is the case how could I possibly
know what the name is? It's creating a new workbook, it could be
called anything, Book1, Book2, Book73. The documents also state that
"it activates any application whose title string ends with Title", but
I have no idea how I could use that, Excel puts the book name AFTER
the title, so if I'm reading this correctly, that will never work
either!

I poked about on the 'net and found a function that seems to do the
same thing:

Public Function BringToFront(objApplication) As Boolean
Dim lngRet As Long

With objApplication
lngRet = apiSetForegroundWindow(.hWndAccessApp)
lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
'the first call to ShowWindow doesn't seem to do anything
lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
End With
End Function

However, this results in "Run-time Error 438: Object doesn't support
this property or method", which it reports for every line in the code.

Any ideas?

Maury


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.access
external usenet poster
 
Posts: 5,939
Default How to force an application to be visible?

Have you tried
oExcelApp.Visible = True

By default when you create a new instace of an office appliation it is not
visible. I have always used the line above.
--
HTH...

Jim Thomlinson


"Maury Markowitz" wrote:

I have a form in Access that calls a complex Excel VBA function to
generate a report, like this...

Public Sub RunReport()
On Error Resume Next
Set oExcelApp = GetObject(, "Excel.Application")
If Err < 0 Then
' excel wasn't running, start it from code
Set oExcelApp = CreateObject("Excel.Application")
End If
On Error GoTo 0

ret = oExcelApp.Application.Run("ReportCreate.xla!BuildR eport",
Me.ReportId)
End Sub

The code works fine, and a report is generated. The problem is that if
Excel was not running when it was called, it opens in the background
somewhere and never becomes visible. On some people's machines a new
instance of Excel is opened whether or not it was already running, so
they can never see the resulting reports.

MS has a command called "AppActivate" that apparently claims to be
able to bring the app forward, but I'm at a loss how to actually use
it:

AppActivate "Microsoft Excel"

results in "Run-time Error 5: Invalid procedure call or argument". The
documents SEEM to suggest this is because a window with that exact
name cannot be found, but if that is the case how could I possibly
know what the name is? It's creating a new workbook, it could be
called anything, Book1, Book2, Book73. The documents also state that
"it activates any application whose title string ends with Title", but
I have no idea how I could use that, Excel puts the book name AFTER
the title, so if I'm reading this correctly, that will never work
either!

I poked about on the 'net and found a function that seems to do the
same thing:

Public Function BringToFront(objApplication) As Boolean
Dim lngRet As Long

With objApplication
lngRet = apiSetForegroundWindow(.hWndAccessApp)
lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
'the first call to ShowWindow doesn't seem to do anything
lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
End With
End Function

However, this results in "Run-time Error 438: Object doesn't support
this property or method", which it reports for every line in the code.

Any ideas?

Maury



  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.access
external usenet poster
 
Posts: 119
Default How to force an application to be visible?

On Aug 8, 11:28*am, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Have you tried
oExcelApp.Visible = True


Oh geez, that easy?! Worked like a champ, thanks!

Maury
  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.access
external usenet poster
 
Posts: 5,939
Default How to force an application to be visible?

I darn near didn't post because I figured you would have already tried that
and for some reason it would not work for you. I then thought back to all of
the times I did not try something that seemed obvious in retrospect and
posted... By the way nice lookin code.
--
HTH...

Jim Thomlinson


"Maury Markowitz" wrote:

On Aug 8, 11:28 am, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Have you tried
oExcelApp.Visible = True


Oh geez, that easy?! Worked like a champ, thanks!

Maury

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table Columns force visible Graham Y Excel Programming 6 July 17th 07 05:38 PM
Force external application to remain 'above' excel sheet David Excel Programming 1 February 16th 07 03:35 PM
Application.visible........ Duncan[_5_] Excel Programming 8 June 27th 06 10:56 AM
Application Visible Frank Excel Programming 6 December 20th 05 08:01 PM
Application.visible help Glen Mettler[_4_] Excel Programming 0 February 16th 05 10:04 PM


All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"