Before Close Code Errors When Closing From Other Workbooks
Nov 21, 2006
I have a workbook which includes a simple set of options on closing such as selecting the front sheet, restoring scrollbars and saving the workbook. To avoid problems with subscripts out of range I am using the ThisWorkbook statement to close the workbook.
This works fine and causes the workbook to close when close is clicked on any excel window. The problem is that excel falls over when it tries to resume closing the other workbooks. I am given (ironically) an error saying "excel has encountered a problem and needs to close". Does anyone know how to work around this?
My code is below:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Toolbars9(True)
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayWorkbookTabs = True
End With
View 8 Replies
ADVERTISEMENT
Sep 7, 2009
I tried to use Workbooks("Inactivebookname.xlsm").Close False
and many variations thereof, but I simply cannot close this workbook when currently another workbook is active.
I have no problem in closing an active workbook with
ActiveWorkbook.Close
View 9 Replies
View Related
Feb 16, 2009
We're using XP Pro using Excel 07
The background is there are about 40 people who use a Excel based program that contains a pivot and a bunch of other tools that they use on a regular basis, this set of tools has a version number. In this excel workbook, it has a function that looks on the network drive that we have and checks the local version vs the version on our network drive, if its wrong, then the user gets a popup stating your tools are out of date, would you like to update, then they click yes and I have these lines of code
Public Function GetNewTools()
Dim MyFullName As String
'Turn off alerts
Application.DisplayAlerts = False
'Open the new version of tools
Workbooks.Open Filename:= _
"Network DriveUpdate.xlsm"
End Function
The update file has this code that executes on fileopen in the thisworkbook section by calling the following sub
The main issue we're running into is near the very end, the code never makes it to "TEST 2". After the first workbooks close, the code just stops running. No crashes, errors, freezes, anything. It just stops running and never makes it to the second msg box.
View 9 Replies
View Related
Sep 29, 2009
I am hoping someone can help. I am new to writing macros and have the following in the this workbook page. When opening the macro does exactly what I want and expect, but does not do the "before close" part. If I select the macro in editor and run it, it does just what I want, so dont understand what is going wrong. Do I have to put in some kind of prompt, or manually run this before close - preferably I would like it to just run.
secondly, I have password protected the workbook, but have to put the password in the macro, is there any way of making this invisible to anyone who then reads the macro....
View 9 Replies
View Related
Aug 15, 2008
1. I am opening several Excel Workbooks and copy ( consolidate) this one into one worksheet in a separate workbook.
2. I want to close those workbooks automatically that I opened once it was copied and pasted to the Target worksheet.
3. The workbook that should remain opened should be the target workbook.
4. The codes below allowed me to open multiple workbooks at the same time and copy them to target workbook but I do not know how to close them automatically.
Sub OpenFilesOnNetworkDrive()
Dim i As Integer
Dim Filt
Dim FiltIndex
Dim Title
Title = "Select files: Hold Ctrl to select multiple files."
Filt = "Excel Files (*.xls),*.xls," & "Text Files (*.txt),*.txt," & "All Files (*.*),*.*"
FiltIndex = 1
View 5 Replies
View Related
Dec 27, 2009
Basically the main workbook opens 2 files at a time performs a calculate in the main workbook and then copies and pastes information in 3 ranges. Then closes the two open workbooks and loops and performs same operations until it hits the maximum loops. My macro is as follows and I have 3 question in capital letters.
View 3 Replies
View Related
Dec 22, 2009
I have several workbooks in a make your day folder categorized under several sub folders. Each workbook has a macro that calls the following macro:
View 2 Replies
View Related
Feb 5, 2010
I have one main workbook that, when opened, opens three other workbooks each in its own instance of Excel. I'd like to know how to close all three of these upon closing this main workbook.
View 2 Replies
View Related
Feb 16, 2007
How can I close the currentmonthend AND previousmonthend workbooks in the following code, but leave workbook "MoEnd Compare" open? I'd like to do some additional comparisons with the "MoEnd Compare" file. I tried the code below to close those two workbooks, but it is not working.
Sub check_month_end()
Dim currentmonthend
Dim previousmonthend
Dim project_current
Dim ptcurrent
Dim yearcurrent
Dim project_previous
Dim ptprevious
Dim yearprevious
Dim r As Integer
Dim c As Integer
Dim l As Integer
MsgBox "This will check project type and year on current and last period month end report."
currentmonthend = Application. GetOpenFilename("Excel Files (*.xls),*.xls", , "Select CURRENT Month End Report?")
previousmonthend = Application.GetOpenFilename("Excel Files (*.xls),*.xls", , "Select PREVIOUS Month End Report?").......................
View 2 Replies
View Related
Feb 25, 2008
I made an Excel based program that uses multiple workbooks with two main workbooks (“Master List” and “Products”) that all the others pull information from. I run into a problem when a user clicks the close X in the upper right hand corner and the entire application closes. I found some code that will let me close all the workbooks but one (the code is put in the “Products” workbook in the BeforeClose event).
For Each wb In Workbooks
If Not wb Is ThisWorkbook Then
wb.Close SaveChanges:=True
End If
Next wb
Is there a way to modify the code so it will close all the workbooks but the two main ones if someone clicks the close X button in the upper right hand corner?
View 3 Replies
View Related
Jan 5, 2009
Is there anyway to change the following code so that it will save and close all workbooks except the one that has this code?
View 3 Replies
View Related
Dec 15, 2009
I'm working on developing a stock option trading system in Excel using a live data feed and VBA. It tends to crash after running flawlessly for a half hour to 2 hours. It seems to crash when loading a support workbook, so I was hoping you could take a peek at my code and see if there's a problem with the way I'm dynamically opening/closing workbooks.
In order to cope with limitations in the amount of live data that I'm accessing (through DDE with Reuters Station), I've split up the data I need into about 600 workbooks, which open when they're needed or close when they're not (through VBA). At any given time, about 35-40 of these workbooks are open.
The main workbook that uses all this live data and support workbooks is set to have the application recalculate every 5 seconds (automatic recalc crashes the program almost immediately). After that refresh, it calls other subroutines, including opening/closing these support workbooks:
View 14 Replies
View Related
Mar 7, 2014
I have completed a long macro, and at the end of the macro I want to close a few workbooks automatically without saving. These workbooks have been assigned variable names.
Is there a command line I can use, that will not prompt the user to save?
Variables:
MARM_fileNM
MARC_fileNM
MAKT_fileNM
Temp_fileNM
View 3 Replies
View Related
Feb 3, 2010
I have an array of data type Variant, who's elements are workbooks opened by a user.
The array size is static, which for now isn't a concern but I can't work out how to close the workbooks in the array via a loop and the usual vba code of Workbooks("file").Close
Code I have that doesn't work is:
Sub Close_Workbooks_In_An_Array ()
Dim dFile (1 to 6) As Variant
Dim i As Integer, j As Integer
' // Some code to open files, set each dFile(i) as a file and then process
' // them. Max value for i is 6
j = 1
For j = 1 To i
MsgBox ("Closing: " & vbNewLine & vbNewLine & dFile(j))
Workbook.(dFile(j)).Close
Next j
End Sub
View 9 Replies
View Related
Sep 5, 2007
I have 30 workbooks closed and i want update a cell (f.e. b4) in all the workbooks.
Need code to open the files, update the data in that cell and close the workbook.
View 5 Replies
View Related
Sep 5, 2007
I have an existing code that runs almost flawlessly but I am running in to formatting cells error (or at least I think that is the problem).
For example, here is a line of code where my error lies:
If Worksheets(FirstSheet).Cells(Counter, ColtoMove) = MoveIf Then
'DO SOME ACTION
If I put my cursor on MoveIf it shows the expect number of 4500016239…….BUT it errors!
When I step through the code and go to the worksheet (or go to the left side of the = in the above code the data in the cell is “4.5E+09“.
I’ve attempted to change the formatting of this cell range to “Text” by the following With statement:
With Worksheets("CreateOrderFormsData")
.Range("AC:AC").NumberFormat = "Text"
End With
Note: if I verify the cells formatting after the above code is ran by rt click on the cell, format cells the Number field is set to “CUSTOM” and the Type: field is set to “TEXT”. Is this the problem? Please read on.
But that did not seem to do the trick…..actually if I now go to the left of the = again (which is now set to text) the data is “###########” in the cell, in the formula bar the number is the expected 4500016239 though but the CODE STILL FAILS!
Am I on the right track…..can anyone assist with this error please?
View 9 Replies
View Related
Jan 26, 2008
Sub CombineWBs()
Dim wb As Workbook
Dim newWB As Workbook
Dim i As Long
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = "C:Budget"
.Execute
Set wb = Workbooks.Open(.FoundFiles(1))
RenameWS wb
wb.Worksheets.Copy
Set newWB = ActiveWorkbook
wb.Close SaveChanges:=False
For i = 2 To .FoundFiles.Count
Set wb = Workbooks.Open(.FoundFiles(i))
RenameWS wb
wb.Worksheets.Copy After:=newWB.Worksheets(newWB.Worksheets.Count)
View 9 Replies
View Related
Jul 8, 2009
I have my VBA Code set up to open a specific file and copy paste that information into this open spreadsheet in a particular sheet.
The only problem I have is that I don't know how to close the document once its opened.
I know that I can manually close it, but I want my macro to take care of it for me.
If anybody has suggestions, they would be greatly appreciated.
Here is my code so far to help out.
Sheets("Ann Ret Data").Select
Range("A1").Select
Workbooks.Open Filename:="P:InvINVpubAndrew EdgarMarket Value Projectperformance_data.xlsx"
Columns("A:G").Select
Selection.Copy
Windows("Qtr-End Market Value Project2.xlsm").Activate
Range("A1").Select
ActiveSheet.Paste
Also the file I want to close is the Performance_Data.xlsx file.
View 9 Replies
View Related
Nov 29, 2013
I'm trying to create a VBA macro which will open external workbooks in a specific folder. thes workbooks will have filenames which are identical to the value in cell B1 of my active workbook. Once open, I would use indirect to pull certain results from that external workbook and then close it. I have a separate macro already which runs through the list. I found a few examples online but they don't seem to work.
View 2 Replies
View Related
Jul 26, 2006
I have 77 excel workbooks that are created each week, they are all in the same directory. I have to open each one and copy the data into a single workbook. The file names change slightly each week.
example: DIST_91124_GROWTH_PRODUCT XXX _07072006.xls The 07072006 is the week ending date and will change. Each of the 77 files has a different DIST_number.
Is there a way to automate this process, it takes me about 4 hours to do it manually.
View 9 Replies
View Related
Oct 15, 2008
My code works well if the worksheet name is Sheet1. It will change constantly. I have alot of other similar workbooks that are not affected and cannot figure this out. Here is the code that I get the error at: ....
View 9 Replies
View Related
Mar 6, 2008
i would like an if macro to pick up if cell dest (i have used a case to define this cell) contains an error or more imoprtantly #REF! then change the offending cells to 0 and put up a message box to put "Check XTA". i have found some that i think may work but i didnt understand them (they had function in them :smask so i couldnt put them in.is there a way to put them in with out functions or could someone point me in the right direction.
View 4 Replies
View Related
May 9, 2008
how to supress the continue,end,debug, message when there is a vba error. The idea being that if there is a bug in my system that I have no realised, I don't want my end user seeing that message! I would preferrable design my own error message to appear instead.
View 2 Replies
View Related
Mar 8, 2005
I am using the close.workbook command in VBA to close a workbook I opened to copy data from. I am getting a message that says "You have a large amount of data on the clipboard. Do you want it available?" What command do I use in VBA say no to this message?
View 5 Replies
View Related
Nov 30, 2009
I have a rather large workbook (30 sheets, 10MB) that has one worksheet with many INDIRECT functions in it (pulling data from the same file, different tabs). I am working to put simple code into the workbook to protect and/or unprotect all worksheets. I have gotten code to work to both protect and unprotect all the sheets, but when I run the unprotect code (see below), and then I go to edit the workbook, data from the sheet with many "indirect" functions temporarily "overwrites" the data on the active sheet (this is fixed when I scroll my mouse over the effected cells). I am developing this workbook for other users, so I'd like to fix this before sending it off to them.
This problem does not happen until after I run the following .....
View 14 Replies
View Related
Jul 15, 2014
the following two statements return the error "Application-defined or object-defined error"
Code:
Sheets("Purchase").Range("PurchaseTax").FormulaR1C1 = "=IF(RC[-1]0,ROUND(RC[-1]/11,2),"")"
Sheets("Purchase").Range("FreightTax").Formula = "=IF(FreightCharge0,ROUND(FreightCharge/11,2),"")"
View 2 Replies
View Related
Mar 25, 2008
I have added this bit of code to change the apperance of entered time from 0835 to 08:35
UserInput = Target.Value
If UserInput > 1 Then
NewInput = Left(UserInput, Len(UserInput) - 2) & ":" & Right(UserInput, 2)
Application.EnableEvents = False
Target = NewInput
Application.EnableEvents = True
End If
And it works like a charm. Except that if the content in one of the cells later is deleted a "Run time error 13" is the result. Debug leeds to the line "If Userinput >1 Then"
Can this error be avoided..?
View 3 Replies
View Related
Apr 15, 2008
I used the code below for Conditional Formatting. This works fine but the VBA-code crashes when I delete more than one selected cell. Is there a simple modification possible to prevent this from happening?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("A1:C250")) Is Nothing Then
Select Case Target
Case 1
icolor = 6
Case 2
icolor = 12
Case 3
icolor = 7
Case 4
icolor = 53
Case 5
icolor = 15
Case 6
icolor = 42
Case Else
'Whatever
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
View 3 Replies
View Related
Mar 8, 2013
I have a macro that opens all workbooks from one directory and runs a macro for each workbook to clean up the data. I cannot figure out how to take all those open workbooks and save them to another directory and close the workbook. Also, I do not want the macro workbook (xlsm) to save. I only want it to close. I am working in 2007 Excel.
View 8 Replies
View Related
Oct 14, 2007
I copied the sheet and redid the format. I renamed the original dashboard sheet from count to "keep" and named the copy after the original "count" Everything still works great - until i either hide or delete the original count which is now named "keep". I get an error at the red colored line below ".publish false".
I have attached an image of the error....
View 7 Replies
View Related