+ Reply to Thread
Results 1 to 6 of 6

VBA to choose "Ok" option of a msg box automatically

  1. #1
    Registered User
    Join Date
    03-04-2014
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    12

    Post VBA to choose "Ok" option of a msg box automatically

    I have a master excel file with lots of agent names in it . I have coded a program in the master file which helps me to fetch a rage of data pertaining to each agent from their personal file. These personal files are saved in the same location where the master file is saved. Each agent file carry the agent name as its file name

    My code works fine but a small problem to be solved. The agent file contains a set of VBA codes and this makes two msg boxes to appearing one after another while closing the file. Because of this I have to manually click on “ok” button for these messages while each file is getting closed.
    As I have hundreds of agent data to be updated, it is making my job difficult and irritating .

    My question is that , can I have VB codes in the master file so that it select and execute “ok” option wherever the msg box prompt in the agent file?

    Please help

    My master file codes are given below

    Private Sub CommandButton1_Click()
    Dim targetwkb As Workbook
    Dim sourcewkb As Workbook
    Set targetwkb = ActiveWorkbook

    Dim Mastersheet As Worksheet
    Set Mastersheet = Worksheets("Master sheet")

    Dim lrow As Long
    lrow = Mastersheet.Range("B" & Rows.Count).End(xlUp).Row

    Dim p As String
    p = ActiveWorkbook.Path
    Dim n As String
    n = ActiveWorkbook.Name

    Dim v As String

    c = 2
    Do While c <= lrow
    v = (p) & ("\") & Mastersheet.Cells(c, 2) & (".xls")
    Workbooks.Open Filename:=v
    Set sourcewkb = ActiveWorkbook

    Dim Salesrec As Worksheet
    Set Salesrec = Worksheets("Sales Record")
    Salesrec.Activate
    Salesrec.Range("E7:E66").Copy
    Workbooks(n).Activate
    Mastersheet.Range("C" & c).PasteSpecial Transpose:=True
    sourcewkb.Activate
    sourcewkb.Close SaveChanges:=False
    c = c + 1
    Loop

    End Sub

  2. #2
    Registered User
    Join Date
    03-04-2014
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: VBA to choose "Ok" option of a msg box automatically

    sorry for that, please find my code below

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-04-2014
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: VBA to choose "Ok" option of a msg box automatically

    kindly help

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: VBA to choose "Ok" option of a msg box automatically

    It depends on what the message boxes are and how they arise. If it's due to code in the agent file, then it won't be easy unless you can change the code in the agent file.
    Remember what the dormouse said
    Feed your head

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

    Re: VBA to choose "Ok" option of a msg box automatically

    If these message boxes appear when you are closing the files then it could be they are part of event code in the workbook(s).

    If that's the case you could try disabling events while you process the files.

    You can do that like this.
    Please Login or Register  to view this content.
    To re-enable events you can use this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    03-04-2014
    Location
    Dubai
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: VBA to choose "Ok" option of a msg box automatically

    yeh man , its working

    I just inserted the suggested code in the master file, immediately after the code which opens the source file.

    Thank you Norie, thanks a lot

+ 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. create "if then" with an "or" option or "choose from" option
    By ojaiojai in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-11-2012, 01:48 PM
  2. [SOLVED] Invoice "Current" or "Overdue" (but need "Paid" option)
    By rwatson in forum Excel General
    Replies: 5
    Last Post: 04-05-2012, 12:16 PM
  3. Replies: 2
    Last Post: 06-26-2007, 02:55 PM
  4. [SOLVED] pictures to work with "data" "sort" option
    By arad in forum Excel General
    Replies: 1
    Last Post: 04-18-2006, 04:15 PM
  5. [SOLVED] Stop users from accessing "Protection" option from "Tools" menu
    By I Believe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2005, 10:50 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