Exit application without closing all the files - excel

I am trying to provide an option to my users to save and close excel application after they finish to complete a specific form. However, it is closing the whole Excel and not only the current Excel workbook that they just used. In other words, if they have 4 different Excel files opened, it will close all of them and not only the current workbook. What am I doing wrong?
This is the code that I am using:
ThisWorkbook.Application.Quit
ThisWorkbook.Save

You must not quit the Application - but close the workbook:
ThisWorkbook.Close SaveChanges:=True
will save and close the workbook.
If it is the only open workbook, Excel gets closed as well.
If not Excel and the other workbooks are still open.

Related

VBA- Closing Workbook Without Saving the File

Hi I'm trying to close my workbook without saving it and I am using the code:
wb.Close savechanges:=False
However, it still closes my workbook and saves all the changes made. Is there a workaround for this or the reason why it keeps saving my workbook? Please help

Screen Updating and Workbook.Activate not working as expected

I work with a a group of six interlinked Excel workbooks that all feed into one summary/reporting workbook (let's call it "Main Report.xlsm").
Since the various workbooks are updated with new information throughout the day as it comes to hand, they need to be saved regularly throughout the day. I have therefore created a simple VBA macro that saves all open workbooks at the press of a button, which I have located as on object on Sheet1 of MainReport.xlsm. The macro works OK and saves all open workbooks as expected, however two aspects of the code are not working as expected:
No matter where I insert ScrenUpdating = FALSE, Excel still displays each workbook on the screen as it saves it. I don't want that because it slows down the save process, plus it looks weird as the macro toggels through each open workbook and the workbooks flash up momentarily on the screen. Since I activate the save macro from Main Report.xlsm, I want the screen to freeze on that workbook whilst Excel saves all open workbooks as a 'background' process. Can anyone tell me how I can make ScreenUpdating work properly with this code?
At the end the macro is supposed to select the 'Main Report.xlsm' workbook, but instead of activating that workbook, Excel seems to get stuck on displaying the second-last workbook in the group of six open workbooks. If I test the code by stepping through it, it seems to work OK, but when I run it from the assigned button on Main Report.xlsm, it does not work. Why would this be happening?
Here is my simple 'SaveAll' macro VBA code:
Sub SaveAll()
Application.ScreenUpdating = False
Dim Wkb As Workbook
Application.Calculate
For Each Wkb In Workbooks
If Not Wkb.ReadOnly And Windows(Wkb.Name).Visible Then
Wkb.Save
End If
Next
Application.Workbooks("Main Report.xlsm").Activate
ActiveWorkbook.Worksheets("Sheet1").Select
ActiveSheet.Range("C4").Select
Application.ScreenUpdating = True
End Sub
Can anyone spot what I am doing wrong?

How can I copy one worksheet from an open workbook to a closed workbook?

I have a workbook that opens to a form the user scans a barcode, and the form closes and closes Excel.
I want to copy one sheet ("STOREDATA") in the open workbook (scanner.xlsm) before it closes, to a closed workbook(REPORT.xlsx) in same directory. It doesn't matter if it opens the closed workbook as long as it closes it.
This would be a pretty simple task.
Open the workbook, make the copy, save it, then close it.
Sub copySheetToReport()
With Application.Workbooks.Open("REPORT.xlsx")
ThisWorkbook.Worksheets("STOREDATA").Copy after:=.Sheets(.Sheets.Count)
.Save
.Close
End With
End Sub
This will place the copied worksheet at the very end.

Excel Workbook open macro reopens closed workbook

I do the following as a macro
Open a list of files
copy some values
Close them
After that when I exit and reopen the file that contains the macro, it also opens the files which I previously opened. even those I had used the app.workbook.close
I'm unable to find the problem out.
Where is the macro located? In a normal module?
At the end, seeing as how you've already pointed the variable at it, you may as well say
currentWB.close False
Then to close
Set currentWB = Nothing
Are there some links between the file that has the macro and the files it creates?

Creating a self-deleting macro in Excel 2007

I'm trying to create a Macro in Excel 2007 that will delete itself when it finishes running and close Excel. The reason I want to do this is that I am going to be sending the Workbook out to other people, and I don't want them to see security warnings about the Macros. Several versions of this Workbook will be generated, so this I don't want to manually run and remove the Macro for each one.
I've tried the following code. It runs without error, but does not actually delete the Macro. If I remove the line "ActiveWorkbook.Close SaveChanges:=True" the Macro is deleted, but this prompts the user to save the Workbook as Excel closes. Is there any way to do this without User interaction?
Dim ActiveComponent
Set ActiveComponent = ActiveWorkbook.VBProject.VBComponents("ModuleName")
ActiveWorkbook.VBProject.VBComponents.Remove (ActiveComponent)
ActiveWorkbook.Save
Application.Quit
ActiveWorkbook.Close SaveChanges:=True
Why not just move your macros to another workbook and have them operate on the workbook(s) you're sending out?

Resources