Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the focus to Excel

Status
Not open for further replies.

jmc014

Technical User
Nov 24, 2007
80
ES
I've got an small issue that I'm a little stuck on.
After exporting data to Excel, the user is asked if he/she would like to open the file that has just been created.
Problem being that the Excel file does not get the focus after it has been opened.

Here's the code:

Me.Form.SetFocus
DoCmd.OutputTo acOutputTable, "CSV_Export", acFormatXLS, MyPath, False

Title = "Program Data File - System information"
Msg = "Exportación completada: " & MyPath & Chr(9) & Chr(10) & Chr(9) & Chr(10) & "Do you want to open the Excel file now?"
DgDef = 4 + 32 + 256
Reply = MsgBox(Msg, DgDef, Title)
If Reply = 7 Then
Response = acDataErrContinue
Else
Appc = """" & [Forms]![CSV_Form]![Destino] & """"
Call Shell("excel.exe " & Appc, vbNormalFocus)


If I delete the delete the Me.Form.SetFocus statement, everthinbg works fine, but when my Db is changed to .mde, I get a 2046 Error message.

Is there any way I can send the focus to Excel after the file is opened?

Cheers guys,
JMC





 
Hi,

Rather than using Shell(), use CreateObject to instantiate an Excel Object and then use the Open method to open the workbook.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Hi,

Thanks for the push.

I got it working with the below:

Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open Appc, True, False
Set xlApp = Nothing


Thanks for your help.
JMC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top