INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Changing the focus to Excel

Changing the focus to Excel

(OP)
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





RE: Changing the focus to Excel

Hi,

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

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Changing the focus to Excel

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close