I have a workbook that has several macros. When the workbook is saved, it cycles through and kicks off several of them.
This works fine, no errors. I have another macro that saves and then emails the workbook. When this macro runs, the same set of macros is launched due to the save method however it errors during one of the macros.
Basically what's happening is that the one macro (derivecountry) unprotects a sheet and inputs a data value. This macro works fine when run independantly but when it runs as a result of the email macr, the sheet does not get unprotected and the error results.
Here is the code line that runs to unprotect but doesn't always work
From this forum I've borrowed code and reused in my own CapEx approval form. The form is originated and goes through three people for approval. Everything seems to work ok on the form but it always forwards to the first approver rather than the next in sequence. I cannot see where the code is wrong.
This macro should copy all data from all worksheets and past them into the sheet named "Consol" however It is not looping and only pastes the one sheet.
Sub LoopThroughSheets() Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets Formula FinalRow = Range("A65536").End(xlUp).Row Range("A2:U" & FinalRow).Copy
I have an Excel 2007 workbook with over a dozen user forms and plenty of code that I have mainly obtained from the web and tweaked to suit my needs. I am a novice with VBA, so not really up to writing anything but quite simple code.
My issue is I have some code set to fire on Workbook_Open that will save a versioned copy of the workbook, to the same network folder that the original resides in, with an incrementally increasing file name. the file is stored on a network, but access should not be an issue as I have full access and have no problem saving to this folder, also the event works fine up until I shut down Excel. I have also tried saving to My Documents to avoid the network issue, same result, worked fine as long as Excel is not closed, fails if I do.
It all works fine until I close down excel completely and re-open, where it then fails to work. There are other events happening in the same Workbook_Open sub that still work fine each time, so the sub is firing on open, but this one event fails. I get no error message at all, just no new file copy created.
The workbook is essentially doing the job of an Access database (I know even less about Access), I have a user form as a main menu and various other forms for various data entry and reporting tasks. I am exiting the w/book via a cmd button on the main menu (I've deliberately restricted users control, as many are not very pc literate). I have conducted numerous trials consisting of running the code from the VBA window, closing w/book via cmd button WITHOUT accepting the std save option and re-opening from Explorer window, closing w/book via cmd button WITH accepting the std save option and re-opening via Explorer and all worked perfectly over many sample runs. But when I closed Excel totally (Not just the w/book), created a desktop shortcut and opened from there, that line of code just doesn't seem to do anything, no error or hang or anything. The only way I can get it to function again, is to re-save the w/book (As either a new file with code edited to suit, or overwrite the original), and keep Excel open whilst only closing this w/book. It then functions perfectly again on opening.
I have enclosed below the Workbook_Open sub and some other subs that append to a user log on opening, these work fine all the time. I enclose the others in case they may have some bearing, as they are also fired from the Workbook_Open sub and show no issues at all.
Any suggestions gratefully accepted as I am struggling. As mentioned above, the ONLY part of the Workbook_Open sub that fails is the line "ThisWorkbook.SaveCopyAs newFileName". I have even added "MsgBox "The new FileName is: " & newFileName" immediately after it, and that displays new filename correctly. It seems to me to be hingeing around the SaveCopyAs event, but I don't want to assume that, being the novice I am.
I'm finding that my add-ins that worked perfectly on Excel 2003 are not functioning on Excel 2007. One of the main issues seems to be loading any UserForms that use the RefEdit control. I get a message saying:
The below code works well if it is on the proper sheet, if the active sheet is not active then it errors- Why? I think I have properly qualified the path to the desired sheet I wish to search on.
Error msg: Activate method of Range class failed
And how do I handle this?
Set Ws = Workbooks("ViewRenameDeleteFiles.xls").Sheets("Item Record List") What = InputBox("Enter the Name You are Searching for its Record#", "Item Name Searching On")
I have written the following code that is supposed to be running on opening a work book. The macro is being called via Application.Run "CreatePT" which is in the this workbook code in a Sub workbook_open().
The code run on its own is fine with no errors... It only bombs out when its called via application.run then its a run time error 1004? ...
I made a new class to make other code less redundant, but it isn't functioning. The class has a "workbook" and "worksheet" member, and these can be accessed through properties. The problem is that the properties don't actually seem to return anything, and no data can be accessed through them.
Private mActiveWorkBook As WorkBook Private mActiveWorkSheet As Worksheet
Property Get wSheet() As Worksheet wSheet = mActiveWorkSheet End Property
Property Get wBook() As WorkBook wBook = mActiveWorkBook End Property
'Sets active WorkBook Sub SetActiveWorkBook(ByVal wBook As String) Set mActiveWorkBook = Workbooks(wBook) End Sub
'Sets the activeWorksheet in the workbook. Sub SetActiveWorkSheet(ByVal wSheet As String) If mActiveWorkBook Is Nothing Then MsgBox ("Invalid WorkSheet selection - WorkBook not defined") Return End If
Set mActiveWorkSheet = mActiveWorkBook.Worksheets(wSheet) End Sub
uDate.wSheet. Range("A1").Value = "foo" ' Expected result - set Cell A1 in sheet testTab = "foo" ' Actual Result - nothing
Dim st As String st = uDate.wSheet.Range("B5").Value MsgBox (st) ' Expected results - bring msgBox of values of cell B5, this cell is not empty ' Actual Result - Empty Message box comes up
So - its fairly obvious to me that something is wrong with the properties. The members themselves are not null, I have verified in the debugger that the class members refer to actual sheets/workbooks, but the properties don't like passing anything out and show as "variable not set" in the debugger. How can I get this to work?? It works fine when I do not use the class, like such:
Dim wB As WorkBook Set wB = Workbooks("Book1.xls")
Dim wS As Worksheet Set wS = Worksheets("TestTab")
Dim st As String st = wS.Range("B5").Value msgBox(st)
But I would like to get the class and properties to work to save clutter elsewhere.
Range Name = AssignDt RefersTo: =OFFSET('Raw Data'!$W$2,0,0, COUNTA('Raw Data'!$A:$A)-1,1)
I perform a routine in VBA which deletes unwanted rows of data from my worksheet. The problem occurs if row 2 happens to be one of those rows. It not only deletes Row 2, but it also deletes my Named Range.
I am trying to compare to values that a user inputs in a user form. It's ok if they are not the same I just want the user to know it. I am only including the part where the if statement is failing:
VB: If Me.VSLongQuant.Value <> Me.VSShortQuant.Value Then MsgBox VerUnBal If VerUnBal = vbNo Then Exit Sub End If End If
I have VerUnBal as Long and defined as:
VB: VerUnBal = MsgBox("The Long and Short option Qunatities are not equal." & Chr(13) & _ "Is this intended to be an unbalanced vertical spread?", vbYesNo, _ "Unbalanced Spread Alert")
I can provide more info as necessary. There are two problems 1) the message box is appearing whether the numbers are equal or not, and 2) clicking No in the message box does not cause the Sub to exit.
I have a protected worksheet with some macros running on it, and I have been requested to make the workbook shared. Trying to implement this, I keep getting the standard "1004 You cannot use this command on a protected sheet" error when applying an autofilter.
Here is what is making this problem a little tricky:
- As the workbook is shared, I cannot do Protect UserInterfaceOnly because you can't change the protection settings on a shared workbook without unsharing it. Needless to say, I cannot unshare the workbook.
- When I protect the sheet, I do allow the user to use autofilter. Consequently, Sheet.Protection.AllowFiltering and Sheet.EnableAutofilter both are on. Still, I keep getting the error.
where shData is the codename of the sheet, lngField is the number of the field and strArg is the filtering criteria.
My guess is, that the error comes from the fact that (for some silly reason) in VBA the .AutoFilter method is used to create a new filter, not only to use an existing one. The members of Sheet.AutoFilter.Filters collection are read-only, and cannot be used to modify the existing filter.
Spreadsheet was created by me and worksheets locked by me with password. Data is maintained by another on the network. Since acquiring a new PC with xl 2003 replacing 2000, none of the worksheets will allow me to unprotect. The "unprotect" menu option is not available (shaded out), and it says "shared" at the top.
I have numerous spreadsheets that work this way, but this is the only one that has this problem. How can I unprotect it to make modifications?
When I protect the worksheet with the spinbutton, the spinbutton is no longer accessible. How can I modify the code below (provided by Leith Ross) to make the spinbutton accessible in a protected sheet?
I need a macro code to unprotect all sheets in a book. The sheets may range from 3 to 20 sheets, with a common password. I want to keep this as contol. Only one person will be using this.
I'm working with this workbook and suddenly the worksheets protected! Although I didn't make any password. I checked it but, I coulden't find any password. see code maybe there is a mistake.
I am using the following code to protect/unprotect a sheet in a tool that i am working on, which seems to work great. It unprotects the sheet runs the code inbetween the two liens of code and then protects the sheet again.
The issue I am having is if i want to go in and edit the sheet without running the code it will not let me. When I go in and type the password to unprotect it says it is invalid. I have typed it exactly how the code reads. I have even tried including the quotes but no luck.
It gives me a error and says my password is wrong. I have user names set to return the password so that it is unlocked for certain people. It works for unprotecting the sheets. I modified it and added it back in to try to do it for the workbook.
[Code] .........
I realize that they " and () around the password are differant, but that's how I last left them. I have tried several combinations and it just gives me more errors saying expected end of statement, etc.
I have a spread sheet that is protected. I would like to have cell G5 unprotected when a checkbox is checked. I am able to unprotect the entire sheet by checking the box but I only want G5 unprotected. My current macro that unprotects the entire sheet is
Sub Checkbox_Clear2() Sheets("Input_Personnel").Unprotect ("1") If Range("J12") = False Then Range("G5").ClearContents End Sub
Is there a way to change the highlighted line where it only unprotects cell "G5".
I have a code that is supposed to go through a folder, open the xls file, replace all of the formulas with values only, then save as a xlsx file to get rid of the macros, however when we get into the next workbook it will not unprotect the sheet. instead it unprotects the origional sheet I sweat this worked last week when i was writing the sections and testing but maybe it didnt. The problem is without unprotecting the sheet i can not paste to it
Workbook 1 opens up, find that the date is expired, then goes through the folder and opens a workbook, is then supposed to unprotect the sheets ( this is where the problem comes in) save all the formulas as values and then as XLS in another folder.
I turned the text red in the offending area, everythign up to this point seems to work fine.
Private Sub Workbook_Open() Dim printquotes As String Dim OrigDate As Date letmesave = True OrigDate = ActiveSheet.Range("n2").Value
I have a protected worksheet showing results of users maths tests. When users try to add data to this worksheet, a Windows Office window appears, advising it is a protected sheet, then gives instructions on how to Unprotect it.
I do not want users unprotecting this particular worksheet.
I have a worksheet where the users need to enter time. I have a macro that captures the time when the user hits Ctrl + t
What I want now is a code which protects the cell after entering the time with Ctrl + t.
I tried to do it, but my macro only works when I don't set any passwords to protect the sheet. How can I pass the password to the code and protect the sheet after the code to capture the time is being executed.
I am working on a worksheet that has been protected off and on. I unprotected this AM, but XL will not allow changes and instructs to unprotect the WS, but it is already unprotected. The WB is not protected and never was. I am at a loss as to how to work around this problem.