Execute When Workbook Saved
Oct 15, 2009I would like to execute a sub when the workbook is saved, what is the procedure for this.
View 3 RepliesI would like to execute a sub when the workbook is saved, what is the procedure for this.
View 3 RepliesNeed VBA code to save column J of open workbook called LmbcAcctsPayable.xls, Sheet1, to same workbook & sheet called LmbcAcctsPayable.xls, Sheet1, when save is not selected.
Reason: The workbook is usually not saved because it is more of a templet with names in column A. Column J is updated with a date when a row is used so I need the column J to copy automatically to the blank templet when exiting without saving (using ThisWorkbook.Save = True in Auto_Close). That way, rows not being used for a long period of time can be periodically eleminated.
I'm looking for a way to execute some code, when the user closes the workbook/excel.
So far, I've found this
I am busy with code that filters and copies from a "source file" using dialogue to choose criteria than adds a workbook and pastes filtered information. I than go back to "source file" and do second filter. My question is this newly added workbook changed from book1 to book2 etc everytime the user will run the macro. How do I go about activating the workbook for second and third paste without it being saved?
Here is name code:
[B]Workbooks.Open ("C:Documents and Settingsabek276DesktopSource File.xlsx")
Options = InputBox(Prompt:="Scheme Code", Title:="Options")
Options1 = InputBox(Prompt:="Scheme Code", Title:="Options")
Options2 = InputBox(Prompt:="Scheme Code", Title:="Options")
[Code].....
I want the excel spreadsheet to "BE Protected" in standard form, and only be "Unprotected" when macros are enabled -- BUT DONT JUMP TO CONCLUSIONS, hear me out, it gets deeper than that
If the user does not enable macros, I want the book to be protected. If they do enable macros, it becomes unprotected.... (On load is good enough, no need to be real-time)..... But, they can save the book, so it would no longer be protected , which is where my question comes in ...
I could use the -unprotect "password"- on load when macros are enabled but this will only work if the spreadsheet was originally protected and is never saved again. This is a problem because this workbook will be given to others and will be saved time and time again.
So, I had a vision :-) .... function 'before save' , protect the sheet using -protect "password"- , allow the sheet to save, and then unprotect back using 'unprotect "password"' so you can continue using - BUT, the problem with this is now I have created an endless loop in theory, because after it unprotects it would want to re-save again because it changed
I have a workbook that I constantly am improving with new macros and VB routines. I sometimes have two versions available for use at the same time. I would like to create a macro or routine that will tell me if the workbook has been saved. A simple cell color change to indicate I've saved would be fine. Also, if I DO save the file and the cell color changes to indicate I have saved, I would like the cell color to change back if any change is made to the workbook. This way I will always know if I need to save or not to keep latest changes.
View 3 Replies View RelatedI currently have the code below that closes all but 1 sheet in my workbook called Main
Is there anyway i can clear a range of cells on a couple of sheets within the workbook when save is pressed?
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
For a = 1 To Sheets.Count
If Sheets(a).Name "Main" Then Sheets(a).Visible = 2
Next a
End Sub
I am looking for a macro that will run on worksheet activation. it needs to run only if the file had been saved from the previous week. would something like this work?
Private Sub Worksheet_Activate()
If application.worksheet.lastsaved = msolastweek Then
range("RANGE").clearcontents
End If
End Sub
I've designed a performance indicator (PI) recorder for up to 12 users, it has a userform allowing the users to input their data and a button to save the data and unload the user form. the data is saved using the following
Dim NextRow As Integer
On Error Resume Next 'skips line if workbook is not open
ActiveWorkbook. Sheets("DATA").Activate 'sets the "data" worksheets as active
NextRow = Worksheets("DATA"). Range("A" & Rows.Count).End(xlUp).Row + 1 ' finds the next empty row
With Worksheets("DATA").Range("A" & NextRow) 'inserts the data from the user form
there follows a series of offsets to slot the data into the correct column,
then this code to save the workbook
ActiveWorkbook.Sheets("reports").Activate
Application.DisplayAlerts = False ' suppress overwrite warning message
ActiveWorkbook.SaveAs "MY PATH"
CreateBackup=False
Application.DisplayAlerts = True
MsgBox "Spread sheet Saved"
The problem I'm having is that when the user then closes the excel application there is a conflict between the users 'saves' i.e. one ultimately will overwrite the other. is there a way round this ?? (this is in EXCEL 2000)
I have working code to unhide specific worksheets from a large number of hidden worksheets and would like to be able to delete all the hidden sheets when the workbook is saved or maybe have a button to delete all the hidden (un-needed) worksheets beside the selection drop-down menu, so that only the selected sheets are saved.
View 4 Replies View RelatedI have a macro in a workbook template,that when the workbook is open it populates a cell with the date and time such as 111711.507. This becomes the contract number for this workbook.. They complete the form or workbook and save it. The next time they open the saved workbook the macro runs and changes the contract number to a new number. I want to disable the macro on the saved workbook from changing the number.
View 2 Replies View RelatedI have one workbook named "Data Master" with numerous worksheets... all sheets are named with the following 6 digit format, eg. 005001, 005024, 005133, 005456, 005763, etc.
I have another directory with files each beginning with the particular 6 digit cost centre number.
I was hoping to have a macro that will... for each worksheet in "Data Master" check a specified directory containing the cost centre files, for the file beginning with the relevant worksheet's 6 digit cost centre number... and simply paste a copy of the worksheet in "Data Master" to the end of the existing sheets in the cost centre file.
I have created a template with a form. Now I'm using (the code is in ThisWorkbook)
Sub Workbook_Open()
frmMyForm.show
End Sub
This runs the form also when opening the template or a saved workbook based on the template. I want the form to run only when creating a new workbook based on the template. How do I do?
When I open any saved Excel file the saved file opens along with a blank workbook titled "Book 1". How can I make it so when I open any saved Excel file it only opens the file I want and not a new workbook every time?
View 2 Replies View RelatedIs there any way of creating a log that logs the last user that saved the workbook including the date and time. I would like the log to be a sheet hidden in the workbook. Not many people will be saving the workbook.
View 9 Replies View RelatedI have the following code:
[Code] .......
What do I need to change in order to make it execute the Call statement on EVERY item in the ListBox2, not the Selections.
I have numerous spreadsheets that I need to open and unhide a sheet, that has XML data stored in cell A1. What I need to do is copy that data in cell A1 and paste it into a text document and save that as an XML file saved as the XLS workbook name with a date stamp.
I'm running into many issues, the main issue is the saving as current file name, and the formatting of the text/XML file.
Here is my current code, which doesn't reference the current file name and is just very generic. Once I get the saving as file-name correct and the formatting of the xml file correct, I will work on it a bit more.
Code:
Sub Test()
Dim Rng As Range
Dim wb As Workbook
Set Rng = Range("A1:A2")
Set wb = Workbooks.Add
With wb
Rng.Copy
[code]....
Is it possible to use a macro to:
1. Open Excel from the Desktop
2. Open a workbook
3. Execute a macro from this workbook
If so, how can it be done, specially point 1?
I have below as part of my
Dim ToPath As String
ToPath = "C:Documents and Settings" & Environ("UserName") & "Desktop"
With Application.FileSearch
.LookIn = ToPath
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
Sheets("Sheet2").Range("A1:A65536").ClearContents
For i = 1 To .FoundFiles.Count
tempbuf = .FoundFiles(i)
tempbuf = Mid(tempbuf, InStrRev(tempbuf, "") + 1, 255)
Sheets("Sheet2").Range("A1").Offset(i, 0).Value = tempbuf
Next i
Else
Exit Sub
it exits the sub which apparently means .Execute is not > to 0.
So my question is, what does the line If .Execute() > 0 checks?
I am 101% sure that there are pdf files under the ToPath folder.
I'm using code from the Ozgrid page: http://www.ozgrid.com/VBA/loop-through.htm
However, once I get to the if statement If .Execute > 0... it does not contain a value. The folder contains 16 files in it, but .Execute does not recognize any of them. Is there a specific library or call that I'm missing??
I've been battling this for sooo long, I just dont know what to do with it.
Using Excel 2003 with WinXP. I'm trying to run macro code automatically whenever time = 9:30:01 (or whatever time I pick) for a stock market trading program, which is why the exact time matters so much. I've been able to get the time to update fine, but unless I click on the worksheet while the time condition is TRUE then my code doesn't run. The time actually is sent to me from the stock data provider and it shows up in a cell as a constantly updating value.
I've tried using the Workbook_SheetChange function and OnTime method, but without luck.
In both cases, unless I activate the sheet the code doesn't run. By activate, I mean that I have to click on the sheet when the values that trigger the code to run would be true. If I do that it works just fine, but sitting around and clicking on a worksheet defeats the purpose of automation. Since I'm trading stocks this has to be very exact, so I can't trust a macro scheduler to do this.
The code further below is what I'm trying to get to run. The time value is in cell L1. In cell L2 I have the following
Attachment 299651
I have turned a Workbook with Macros into an add-in. The macros work perfectly for the intended purpose: copy selected data in a special way and put it into an e-Mail message.
I used the CustomUI Editor to assign a macro to a Ribbon button.
However, when I turn it into an add-in and click the Ribbon button, it doesn't work on my machine or any other machine, with an error that says "Cannot run the macro 'CreateListofInventory'. The macro may not be available in this workbork or all macros may be disabled.
My macros are not disabled, and the add-in doesn't even work in the book where the macros reside.
I have two userform one if useing the getopenfilename to popluate a listbox. and then i use these listbox item withen this code to copy the files into a new folder. This works ok.
Then i copy a program into the same folder jpegresize.exe this program makes resized images of all files in its directory. by defult this program should only deal with these files. though what is happening is instead of using the files in the new folder it running on the files where the originals where copied from. (hope that makes sence). Though if i run jpegresize.exe from the new folder or command prompt it. It runs like it should. So i cant figure it out is there somethink the the shell and wait is passing that it shouldnt be.
How do I have a workbook execute VBA code when I hit 'Enter' anywhere on a specific sheet? I don't need the code to execute when I hit 'Enter' on any of the other sheets in the workbook, just a specific sheet.
View 11 Replies View RelatedI coudn't find anything on this forum on this subject.
Is there a way to execute [trigger] a macro from within a formula?
e.g. Based on an IF statement result, execute macro1 if true or macro 2 if false?
modytrane
I need a macro that will execute the F2 function key so that the cell can be edited.
View 7 Replies View RelatedI have this very simple code below that I use to delete a row if its marked as 'false' in column M. This works quite well, but I want to expand it. I use this in a workbook that can have name different sheet names in a month, and I want it to automatically go through all the sheets and do this...except for 2 sheets named addressess and sheet1. Is there something I can add to this macro that will loop through all the other sheet names (regardless of name) and execute this?
Sub DelRow()
With ActiveSheet
.AutoFilterMode = False
With Range("m1", Range("m" & Rows.Count).End(xlUp))
.AutoFilter 1, "false"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
End Sub
Assume a cell -- say A1 -- has a long formula in it. If I select A1, press F2 to "Enter" the cell, then I have a blinking 'l' indicating the cursor/pointer position WITHIN the cell.
Is there any way to control the position of the blinking 'l' (or whatever it is called)? For instance, in a long formula, I would like to write a macro which could transport the blinking 'l' to midway into the formula string.
Alternatively, can I make a partial selection WITHIN a cell and run a macro on it. For instance, if cell B1 has a heading "Dec 2007" and I highlight just the "Dec" portion of the string, I would like to execute a macro to color it red. I have a simple macro that can do it to the entire cell, but not to only part of the cell contents. Is there any way for VBA to be active when I am WITHIN a cell.
Sub Font_Red()
'will add red color to ActiveCell font
Selection.Font.ColorIndex = 3
End Sub
I tried the following code but it shows an error:
Sub test2col()
Sheets("Sheet6").Cells.ClearContents
Sheets("Sheet6").Range("A:B").Value = Sheets("Sheet1").Range("A:B").Value
Sheets("Sheet6").Range("D").Value = Sheets("Sheet1").Range("C").Value
End Sub
It said
Sheets("Sheet6").Range("D").Value = Sheets("Sheet1").Range("C").Value
End Sub
has error.
Does a Sub not support to use Range more than one time? If so, do I need to write many Sub to do it?
How do I let a macro execute a certain key strok combination, such as Alt, D, G, H?
(Didn't really know what to search for...)