+ Reply to Thread
Results 1 to 4 of 4

Insert a key function in VBA script

Hybrid View

  1. #1
    Registered User
    Join Date
    05-26-2005
    Posts
    12

    Insert a key function in VBA script

    I need a function that is going to hit the "Y" key for me. When I run a certain macro, it wants to send a file to a certain location to update it and replace the old one. During this I have to hit the "Y" key to say yes. I want to add something to the script so I dont have to do this and then finally the script will be able to run on its own without me.

    Trevor

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good evening Bowes13

    Use this command at the start of your code:

    Application.DisplayAlerts = False

    and this at the end of your code:

    Application.DisplayAlerts = True

    This will force the macro to not ask you a question, but choose the default option on your behalf (which would be OK - overwrite the file).

    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    05-26-2005
    Posts
    12
    What if my default is No?

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi Bowes813

    What I said in my answer was correct, but I think perhaps I could have explained it a little better. this command will set your default value for the question to true and answer the question for you. Indeed, this is what the Excel 2003 help file has to say about the DisplayAlerts property:

    "When using the SaveAs method for workbooks to overwrite an existing file, the 'Overwrite' alert has a default of 'No', while the 'Yes' response is selected by Excel when the DisplayAlerts property is set equal to True."

    HTH

    DominicB

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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