Problem when Excel Not Maximized

G

Guest

Okay guys, this is a weird one.

I'm running the sample code below from Access to dump data to a worksheet,
which works fine except for one thing.

If Excel is already open when my code runs AND is minimized, the following
happens:

1. Access gives focus to Excel and
2. Excel pops up (gets the focus), but does not maximize

I do not want Excel to have focus until all of my code runs and I want it to
show maximized. Interestingly, this does not happen if Excel is maximized
already (like when Alt-Tabbing to different open applications). It also does
not happen if Excel is NOT open when my code runs.

The main reason this is an issue is because I am using the status bar in
Access to let my users know the progress of the procedure and I don't want
them to see the worksheet as it is being populated.

I am using objXL.Visible = True at the end of my code, but this doesn't make
any difference. The code below is just a small portion of code in my
procedure, but seems to be where my issue is.

Any help with this would be appreciated.


SAMPLE CODE:


'Open workbook and Excel, if needed.

If fIsAppRunning("Excel") Then
Set objXL = GetObject(, "Excel.Application")
boolXL = False
Else
Set objXL = CreateObject("Excel.Application")
boolXL = True
End If

'Set source file and path.

FileName = DLookup("[TemplateFile]", "tblPaths", "[Process] = 'Daily Sum
Report'")

PathName = DLookup("[Path]", "tblPaths", "[Process] = 'Daily Sum Report'")

'Set Excel workbook.

Set objActiveWkb = objXL.Workbooks.Open(PathName & FileName)

Set objActiveWkb = objXL.Application.ActiveWorkbook


Thanks,
Clint
 
P

Peter T

You could use an API's first to get the window handle then set it to
foreground but try
AppActivate Application.Caption

Regards,
Peter T
 
G

Guest

Thanks for the tip! I will try it out.

Clint

Peter T said:
You could use an API's first to get the window handle then set it to
foreground but try
AppActivate Application.Caption

Regards,
Peter T

cherman said:
Okay guys, this is a weird one.

I'm running the sample code below from Access to dump data to a worksheet,
which works fine except for one thing.

If Excel is already open when my code runs AND is minimized, the following
happens:

1. Access gives focus to Excel and
2. Excel pops up (gets the focus), but does not maximize

I do not want Excel to have focus until all of my code runs and I want it to
show maximized. Interestingly, this does not happen if Excel is maximized
already (like when Alt-Tabbing to different open applications). It also does
not happen if Excel is NOT open when my code runs.

The main reason this is an issue is because I am using the status bar in
Access to let my users know the progress of the procedure and I don't want
them to see the worksheet as it is being populated.

I am using objXL.Visible = True at the end of my code, but this doesn't make
any difference. The code below is just a small portion of code in my
procedure, but seems to be where my issue is.

Any help with this would be appreciated.


SAMPLE CODE:


'Open workbook and Excel, if needed.

If fIsAppRunning("Excel") Then
Set objXL = GetObject(, "Excel.Application")
boolXL = False
Else
Set objXL = CreateObject("Excel.Application")
boolXL = True
End If

'Set source file and path.

FileName = DLookup("[TemplateFile]", "tblPaths", "[Process] = 'Daily Sum
Report'")

PathName = DLookup("[Path]", "tblPaths", "[Process] = 'Daily Sum Report'")

'Set Excel workbook.

Set objActiveWkb = objXL.Workbooks.Open(PathName & FileName)

Set objActiveWkb = objXL.Application.ActiveWorkbook


Thanks,
Clint
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top