I got a workbook that automatically opens a UserForm.
The workbook itself I hide using Application.Visible = False
While in the UserForm the user is able to create a new workbook (.CSV file) and this all works.
But if the user tries to close the newly created workbook it will ask if you want to save it AND also want to save the original workbook (closing it in the process). If I select No on the first menu (new workbook) and cancel on the second (the original workbook) both workbooks remain open. If I don't select cancel on the second menu both will close.
Is there a way to hide my workbook and later on closing a different workbook without being forced to close the hidden workbook?
Update:
A current workaround I have is putting a button on the UserForm to close any newly created workbook with Application.DisplayAlerts = False enabled during this process (and of course setting it to true after) .
Related
I'm having other problem, i want my userform to show up but i want ONLY the active workbook hidden on the same time.
The problem is that all the other excel files that i have open, also became hidden, and when i try to open some other workbook, it doesn't open and automatically becomes hidden also.
thanks
I tried to show the userform from the workbook, and at the same time, that workbook becomes hidden, but the other excel files i have open also becomes hidden.
Sub Abrir_Templates_BackOffice()
Application.Visible = True
TemplatesBackOffice.Show
End Sub
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?
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.
I have a workbook ("CodeBook.xlsm") that runs code using a BeforeSave event. When a user has multiple workbooks open and chooses to quit excel via File/Exit, the user is prompted whether to save workbooks, and if yes to CodeBook.xlsm, then the BeforeSave code is run. The problem is, at that point the ActiveWorkbook may not be CodeBook.xlsm, unless that happens to be the workbook that the user was in when he/she selected Exit Excel. If the user quit excel from another workbook, the BeforeSave code is running but the activeworkbook is some random file of the user, so all the references to specific worksheets and ranges in the BeforeSave code do not work.
I have tried various ways using a Static declaration to retain the name of CodeBook and workbook().activate to activate it when the application is quitting, but when BeforeSave runs, it can't pick up the name CodeBook anywhere, short of hard-coding the name into the code.
Any suggestions? How to retain a variable name in memory when there is no code running, but is there when a user initiates a quit excel, OR how to activate a specific workbook when Excel is quitting from a user command and not from application.quit. Using excel 2010.
I overcame this by including a reference to the specific workbook.
For example, this code simply saves the date/time stamp in cell A1 of Sheet1 before closing the document. By adding ThisWorkbook, it works on the specific workbook that the code resides in. If you don't add ThisWorkbook then it will work on the active workbook when the user quits.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Worksheets("Sheet1").Range("A1").Value = Now()
End Sub
Place this code in the ThisWorkbook module.
I have a workbook lets call it workbook A with different buttons on it. One of the buttons launches a UserForm to ask the user for some information to be inputted into a separate workbook. After the user clicks OK if open up workbook B and inputs the data. The problem is the user has to minimize workbook A to start working on workbook B.
I have tried
ActiveWindow.Visible = False
and also
Windows("MyWorkbook").Visible = False
These make the window disappear completely. I just want to minimize the window. I have also tried recording what happens when you minimize but nothing is recorded for minimizing a window. Any help is much appreciated.
Try this:
ActiveWindow.WindowState = xlMinimized
or
ActiveWindow.WindowState = 1