Solved

Excel VBA: Closing Message Box Automatically in

Posted on 2011-02-22
4
953 Views
Last Modified: 2012-06-27
I'm writing a VBA Module in Excel to open other Excel workbooks.  When opening the workbooks I get a couple of message boxes that pop up.  I need to know how to automatically close these message boxes to allow my script to continue mining the data.

If I'm missing some simpler way to mine data from a bunch of workbooks. please let me know.




Here is a snapshot of my code as of now:
Sub MineTimesheets()


SearchPath = "C:\Documents and Settings\USER\Desktop\Time Sheets"


Dim NumWorkbooks As Integer
Dim i As Integer
Dim Data() As String

With Application.FileSearch
    .NewSearch
    .FileType = msoFileTypeExcelWorkbooks
    .LookIn = SearchPath
    .SearchSubFolders = False
    .Execute
    NumWorkbooks = .FoundFiles.Count
End With


For i = 1 To NumWorkbooks
    ReDim Data(1 To i)
    Data(i) = Application.FileSearch.FoundFiles(i)
    Worksheets("Sheet2").Cells(i, 1).Value = Data(i)
Next i


Workbooks.Open ("C:\Documents and Settings\USER\Desktop\Time Sheets\2011-02-16 to 28 Hotchkiss, Caleb.xls")
Application.DisplayAlerts = False
Workbooks(2).Worksheets("Time Sheet").Cells(5, 5).Value = 7
ActiveWorkbook.Close Savechanges:=True
Application.DisplayAlerts = True

End Sub
0
Comment
Question by:sagetechit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 34953115
One possibility is to replace the messge boxes with messages written to the status bar -- no need for any user action.  Here is some code:
Application.DisplayStatusBar = True
Application.StatusBar = "Clearing worksheet rows - Please Wait!"

Open in new window

0
 

Author Comment

by:sagetechit
ID: 34953227
The code that Helen Feddema provided still allowed the popups to appear, so it didn't solve my problem.

I did notice that
"Application.DisplayAlerts = False"
prevents one of the popups, but it does not prevent the "This workbook contains links to other data sources. . ." popup.
0
 

Accepted Solution

by:
sagetechit earned 0 total points
ID: 34953596
I discovered that the solution is nesting my code in this:

Application.AskToUpdateLinks = False
    MyCode
Application.AskToUpdateLinks = True
0
 

Author Closing Comment

by:sagetechit
ID: 35196678
Correct answer.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question