+ Reply to Thread
Results 1 to 3 of 3

Application.Sendkeys to copy Immediate Window - Is it dangerous?

  1. #1
    Forum Contributor
    Join Date
    10-11-2013
    Location
    Austria
    MS-Off Ver
    Excel 2010
    Posts
    136

    Application.Sendkeys to copy Immediate Window - Is it dangerous?

    Morning,

    I'm looking for some advice here.
    In a workbook being used by a few different people, I print a few things like error messages to the immediate window to review later if needed.
    Seeing as the window clears when the workbook is closed(correct me if i'm wrong), I'm using this to copy everything in it to a sheet before closing so it's stored somewhere:
    Please Login or Register  to view this content.
    Even as I'm typing this I realise I could just send info directly to the sheet instead of the Immediate Window, but now that I've got this far...
    I read around the place that using SendKeys can be dangerous - can anyone tell me why? And would it be advisable to use them for such an application?

    Thanks
    Michael

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Application.Sendkeys to copy Immediate Window - Is it dangerous?

    Michael

    Don't know about dangerous but SendKeys is certainly unreliable.

    Best stick to outputting directly to a sheet.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor S O's Avatar
    Join Date
    06-25-2015
    Location
    England
    MS-Off Ver
    Office 2010 + 2013 + 2016
    Posts
    103

    Re: Application.Sendkeys to copy Immediate Window - Is it dangerous?

    If you enable access to the VBProject in Excel settings you can access the immediate window directly - however your best (and safest) option is as Norie has advised which would be to write the output directly to a hidden sheet rather than copy/pasting. I would avoid SendKeys at all costs, there is usually always a better way.

    You could use this Sub in a normal code module:

    Please Login or Register  to view this content.
    And then in your project, simply do a find/replace (Ctrl + H) to replace "Debug.Print" with "DebugToSheet"

    The other option would be to create a custom error handler that prints to a log file.
    Last edited by S O; 09-18-2015 at 04:00 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Gain Control of SQL Login Window and SendKeys
    By AlvaroSiza in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-21-2014, 05:56 PM
  2. SendKeys in Active Window
    By roki4 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 03:35 PM
  3. Application.Sendkeys for Mac Excel
    By nalgene5622 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2012, 09:42 PM
  4. sendkeys windows security pop-up window
    By ljoseph in forum Excel General
    Replies: 0
    Last Post: 11-17-2011, 05:35 PM
  5. easiest way to get window focus with sendkeys?
    By qwyz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-27-2009, 09:38 AM
  6. Application.sendkeys help
    By viruzman in forum Excel General
    Replies: 1
    Last Post: 03-26-2008, 10:13 PM
  7. The application SendKeys
    By Jim333 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2005, 12:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1