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
Bookmarks