Select Previous Active Window
Mar 25, 2009
I have multiple excel workbooks open at the same time. I need to run a macro on one of them every 15 min but I need to return to the active window when the macro is done. How do I read what window is active then return to it when the macro is done?
Sub AutoSave()
dTime = Now + TimeValue("00:15:00")
Application .OnTime dTime, "AutoSave"
Windows("data.xlsm").Activate
Sheets("Data").Copy
Application.DisplayAlerts = False
ActiveWorkbook. SaveAs Filename:="c:excel" & Format(Time, "hhmmss"), FileFormat:=xlCSV
ActiveWorkbook.Close
Application.DisplayAlerts = True
Windows(1).ActivatePrevious
End Sub
View 2 Replies
ADVERTISEMENT
May 8, 2007
I've built a macro to run a loop that opens excel files, prints certain sheets and closes them. I have the macro working - to some degree. here is my code (this is excel):
Sub RMPProducer()
OldPath = "S:RMBS_Performance_Analytics Analysis1 Staging Folder For Monthly Model Templates2007200704VVDeals"
Dim t As Workbook
Dim s As String
Dim a As Window
With Application.FileSearch
.NewSearch
.LookIn = OldPath
.SearchSubFolders = False
.Filename = "*.xls"
.MatchTextExactly = True
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
s = .FoundFiles(i)
I have 2 problems. First problem is that I am trying to add a function to make the window close once its finished printing. This actually works - but it limits my loop iterations from i = 1 to 2 (so it only runs 2 times and I'm not exactly sure why). If I don't include the statement - this can run for up to 7 - 8 times (these are very large files) then excel runs out of memory. Unfortunately, i can't set the loop to run from i = anything other than one.
So What I would prefer is to be able to make the "ActiveWindow.close" command work - because this way I can run the entire loop. But I'm not sure how to. I tried window referencing, I tried adding a new active Window so when the file opens, its opening in the active window already, but nothing works.
Preferably, I need to be able to reference both windows, as my next macro will involve referencing 2 windows (one static - always open) and the other the loop above.
View 4 Replies
View Related
Apr 27, 2009
I'm trying to enter this very simple macro that is supposed to switch from one active window to another. However, I'm getting an error, which I can't quite figure out. Here is the
View 2 Replies
View Related
Jul 4, 2007
Dim iStartBook As Long, iNewBook As Long
iStartBook = ActiveWindow.Index
ActiveWindow.NewWindow
iNewBook = ActiveWindow.Index
I'm trying to grab the "2" that .NewWindow generates. The above gives 1 both times, despite the obvious 2 in the caption after you run it. So what property works? What does .Index mean here?
View 9 Replies
View Related
Feb 7, 2007
I'm trying find a way in VBA to make a particular cell the top left one in the active window.
View 9 Replies
View Related
Dec 14, 2008
I have a worksheet with frozen panes (Row and Column). I have hyperlinks that jump to the this worksheet. Is there anyway to have the window position itself so the active cell is in the upper left corner of my frozen panes?
View 9 Replies
View Related
Aug 21, 2006
In an open excel file, in the top left-hand corner, the file name is always "Microsoft Excel - Your File Name".
does anyone know how to have the top-left hand corner show "Your File Name" only?
View 9 Replies
View Related
Apr 15, 2013
I compared data between excel worksheets all the time, well recently my computer was upgraded from Windows XP to Windows 7 and since then I have not been able to figure out how to have an Excel file to open in the Excel window selected(or last active window) when I have more than one workbook open. Is there a way to do this?
View 5 Replies
View Related
Jun 7, 2014
I was just wondering if it possible to create a macro that permanently increases the height of a workbook by a set increment
I have several workbooks that i have the code below assigned to
[Code] ......
So when they open they resize to that set size and position. and what ive been doing if i need to resize (which is often) is just adjust the values in the above code.
Not that the way ive been doing it is difficult but i was thinking how great it would be if i could have a macro i could run that permanently adds 9 to the .Height and subtracts 9 from the .Top
View 4 Replies
View Related
Aug 22, 2014
I'm listing through sheets and have Sheet2 for drop-down lists.
Sheet2 is not visible, but when I click on Cmdbutton It appears so that I can change values in drop-downs. When I hide Sheet2 again, I want to be back on sheet before Sheet2.
My code for open and close sheet2 :
[Code].....
How can I do that ?
View 2 Replies
View Related
Jun 3, 2006
I need to locate the address of the previous active cell without triggering a selectionchange event (as this is where my code is activated from). Here is what I am currently using unsuccessfully:
strPrevAddress = ActiveCell.Previous.Address
View 4 Replies
View Related
Jun 18, 2014
So the constraints are
1. if there's a value in name or names count => must be at least one value in test1 or test2
2. last value in names count must be equal to the sum of trues in B1:B4 Problem Is it possible to identify once any of the cells in A9:D12 are activated that once that range is deactivated I run the check to make sure the constraints are met, and populate default values in the case they are not?
Is it possible to identify once any of the cells in A9:D12 are activated that once that range is deactivated I run the check to make sure the constraints are met, and populate default values in the case they are not?
Trying to figure it out with a some combination of: checking if the last cell I was in was in the range and I am no longer in that range; using the selection change change event?
[Code]....
Attached File : HelpMeWorkbook.xlsx
View 8 Replies
View Related
Jun 28, 2012
let's say I run a macro from a button on sheet 3, macro process on sheet 10. Is there a way that the macro would automatically go back to sheet 3? Like a "Back" button on IE. I can't code Sheets("sheet 3").Select because I want it to do the same thing on sheet 4,5,6...
View 3 Replies
View Related
Feb 28, 2014
I have found this code by searching witch is perfect
Code:
If Target.Cells.Count > 1 Then Exit Sub
Application.ScreenUpdating = False
Cells.Interior.ColorIndex = 0
With Target 'With the cell that was selected,
.EntireRow.Interior.ColorIndex = 8
.EntireColumn.Interior.ColorIndex = 8
End With
Application.ScreenUpdating = True
The point is that i want to retain the previous formatting of cells when i select another cell. And also i would like to create a switch to turn the Worksheet_SelectionChange event on and off. The tricky part is here i guess, becouse i would like when turned off to retain the previous formatting also.
View 2 Replies
View Related
Oct 5, 2011
The below code opens up the printpreview window. This does not allow to select the correct (or change) printer it will automatic use the default printer.
Is there a way for the code to open the print window so I can change the printer and select number of copies?
Code:
Sub Print_Button()
Dim ws As Worksheet, cell As Range
Set ws = Sheets("main")
Set cell = Range("g2000").End(xlUp)
Do Until cell.Value ""
Set cell = cell.Offset(-1, 0)
Loop
ws.PageSetup.PrintArea = ("A2:" & cell.Address)
ws.PrintPreview
End Sub
View 3 Replies
View Related
May 1, 2013
Below is a macro I'm trying to create. The basically it's supposed to be a quick simple macro to save lots of time. I want to select current tab, move/copy (create copy) to the end....then select the tab I've just copied and copy paste special the values (then rename the tab to todays date) FYI the tab I'm copying is called rebuy shipping.
However, I want to then do the same at a later date with the most recent tab, but with the below code it always selects and copies the original tab:
Sub macrorebuy1()
'
' macrorebuy1 Macro
'
' Keyboard Shortcut: Ctrl+k
'
Sheets("Rebuy Shipping").Select
[Code] .....
I assume this is a simple error. I've tried inserting Activesheet.previous.
View 2 Replies
View Related
Aug 5, 2014
[Code] ......
What is wrong with above code? I am not able to select previous A15 cell, when macro is selected from C1 cell ( B row is filtered to hide ).
View 1 Replies
View Related
Dec 10, 2009
I am wanting to configure approx 100 drop down boxes to all point to the same range of data, approx 40 names, but once the name has been selected, none of the other drop down boxes will be able to select that name.
eg.
range:
Dave
Mike
John
Steve
select Dave in drop down box in cell B5. Next cell, B7, I want a drop down box without Dave in it.
If i then change my mind, and select Steve in cell B5, it will automatically adjust cell B7 to allow Dave as he is now no longer selected in cell B5.
View 9 Replies
View Related
Jan 20, 2014
I need a formula to automatically change the summary column according to the month we are in.
Ie:
Last Months Data
Nov
Dec
Jan
Feb
1
8
1
7
4
7
9
2
9
'Last Months Data' column should show Dec. However, as we move into February and I complete the 'Jan' column, I would like 'Last Months Data' to automatically change to show Jan's data - is this possible?
I was previously told to use the following formula but this would automatically select the current months data and not the previous months data which is what i need - =INDEX(B2:L2,MONTH(TODAY()))
View 2 Replies
View Related
Jul 17, 2014
I am trying to select the active row and the next 21 rows down, so in all 22 rows should be selected after the macro runs.
View 4 Replies
View Related
Jan 20, 2010
I've manage to do this a while ago, unffortunaly my hard drive got damaged.
View 3 Replies
View Related
Feb 5, 2007
I need to select the row for the active cell without using an explicit RC address. I don't seem to be able to make the syntax work.
View 2 Replies
View Related
Mar 30, 2014
I am trying to select a shape in a cell and place a cell reference into the shape. I know the cell address, but do not know the shape reference. (The row that the cell and shape reside came from copying the row from another sheet and inserting it into the current sheet). I can not seem to come up with the correct code to accomplish this. Right now I have:
Cells(r + 1, 48).Select
ActiveCell.Shapes.Select
ActiveShapes.Formula = "$AW:" & r + 1
Where r+1 is the row where the line finally resides after insertion and "AW" is the column to the right of the cell where the shape resides.
I have tried to put the cell reference into the shape at the location where it is copied from but the reference is not dynamic and I can not seem to get it to be. Another issue that will arise is that the rows in the new sheet will probably be sorted and I question if the cell reference will follow the shape's new location.
View 7 Replies
View Related
Apr 23, 2014
I want a simple macro which will go to the cell in row one in the active cell's column
View 2 Replies
View Related
Aug 21, 2009
Using vba how do I tell a macro to select the row that the active cell is in?
I'm just using a basic delete Row macro but I'd like for the macro to automatically select the entire row when it's time to delete instead of me highlighting the section.
View 2 Replies
View Related
Oct 8, 2013
I need a macro that will select row 15 in the active column. (basically returns to the top of the data where rows 1-14 are frozen in place, only in the current column).
I have been able to accomplish the opposite (skip to specific column while maintaining active row) by using the code below:
Range("V" & (ActiveCell.Row)).Select
But it does not work when I try the reverse:
Range((ActiveCell.Column) & "15").Select
View 3 Replies
View Related
Oct 14, 2013
If statement, any way where I can, when I run the macro, choose active cell?
Ex.
Start macro
and it will ask for active cell,
check if active cell higher then 0
then set cell to color red
I have this atm:
Code:
Sub LookForValue()
' Declare Current as a worksheet object variable.
Dim Current As Worksheet
' Loop through all of the worksheets in the active workbook.
For Each Current In Worksheets
[Code] .........
View 8 Replies
View Related
Jun 10, 2014
What is the difference between the two ?
When should I use each one ?
View 4 Replies
View Related
Jul 24, 2014
I have the following code Range("M402").Select
This very simple code brings me to M402 everytime I click on the button.
However, I would like to stay in the same column that I am at the moment when I click the button, and go to row 402. (i.e. if I am in cell "Z56", I would like to be redirected to "Z402" when I click the button.
View 3 Replies
View Related
Apr 19, 2014
So for example if I have a1, a5, and a6 selected, I want to be able to select row 1, 6, and 7 in one action. Is there a hotkey for this, and if not what macro could I use?
ActiveCell.EntireRow.Select only gives me one row. I want to be able to select all of them at once.
View 1 Replies
View Related