Im currently trying to create a macro to protect and Unprotect a sheet.
I have gotten it to work fine with protecting and unprotecting the worksheet in question.
The only problem i have is if the incorrect password is entered when trying to unprotect the worksheet. I get a Error 1004 telling me the password is incorrect and to ether Debug or End the macro.
My question is. Is there any way i can stop this and instead show a message saying to reenter password ?
Current code i have is (please note that the if Err 1004 doesnt work as yet) :-
Private Sub TogAuditSheet_Click()
Dim strPassword As String
Dim strPasswordcheck As String
If TogAuditSheet.Value = True Then
strPassword = InputBox("Enter the password to Protect & Hide the Audit Findings Workheet")
Worksheets("Audit Findings").Protect Password:=strPassword, Scenarios:=True
TogAuditSheet.Caption = "Audit Findings Hidden. Click to UnProtect"
Sheets("Audit Findings").Visible = False
Else
I am using the following code to enable users of a form to made make selections by adding a tick in one of the boxes by clicking on it. It works fine with thesheet unpotected but when I protect the sheet with cells E33:k33 unlocked i get Run Time Error '1004'
Unable to set the Name property of the font class.When I debug, Target.Font.Name = "Marlett" is highlighted.
I am getting the following error: Run-time Error '1004': Copy method of Worksheet class failed. after adding 53 worksheets to a workbook using VBA. I found several posts concerning this error in the forum. However, I did not find any responses that address the root cause or provide a solution.
Very new to VBA and having trouble with a simple macro running in 2003 that copies and pasts to another worksheet. Code as follows:
Private Sub CopyResults_Click() 'Select the filtered data and copy it Range("A23").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Range("F19").Select ' Open the template and copy in the data Workbooks.Open Filename:="C:Athens Verification DataTemplatesVerification Template.xls" Workbooks("Verification Template.xls").Activate ActiveSheet.Range("A1").Select ActiveSheet.Paste ActiveSheet.Range("A1").Select Application.CutCopyMode = False End Sub
When I run CopyResults, the sheet is opened and the data copied correctly, but I get a runtime error 1004 past method of worksheet class failed, with the line 'ActiveSheet.Paste' highlighted. Don't get this when I run the same macro in 2000.
I am getting the following error when i am clicking a Button on sheet1 which is generating duplicate of sheet1.I am trying to delete the button when duplicate is created..Error is:" run-time error '1004' Unable to get the buttons property of the worksheet class" at this line in code"ActiveSheet.Buttons("CmdHistory").Delete"
I'm using Excel 2013 and I'm getting an issue in vba I can't figure out. (This is something I've done several dozen time before) But everytime I try to copy a sheet in a workbook,
the if stattement works perfectly and does exactly what i want except when it comes to the else part. if there is no error the statements are run perfectly but if there is an error (in this case the error is generated when a match cannot be found in the spreadsheet) the else statement doesnt kick in and post the msgbox. the code just crashes. and returns an error 1004 on the line i have highlighted in yellow
res = WorksheetFunction.Match(invvar, Columns(1), 0) If Not IsError(res) Then
Before I go into details I am working in one workbook with several worksheets(Tabs) in the workbook. I have three Buttons on one tab. the button I am having trouble with is the third. I want to insert a column in a separate tab that contains approximately 87,000 rows of data. I then want to do a row count and select the empty cells in the inserted column and put a formula in there. I have tried a loop VBA code and it works, but it takes about 30 minutes to run all the way through. The underlined portion is what is higlighted with error 1004: Application-defined ro object-defined error. I am not sure how to fix this. This is what I have now:
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.
I have a file that needs to be locked down so that the end user does not have the ability to enter data where they shouldn't. The end users are very Excel illiterate, and have proven that I need to have high security in place. Here is my current VBA code - the purpose of which is to hide/unhide rows depending on data entries. (Disclaimer: this code may not be pretty as I am a VBA rookie, and I've begged borrowed and stolen from about 10 other threads on this board to get where I am, and yes it works).
Code:
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address(False, False) = "C7" Then Call Changeto1 If Not Intersect(Range("c9"), Target) Is Nothing Then Rows("15:44").EntireRow.Hidden = True Rows("15:" & Range("c9").Value + 14).EntireRow.Hidden = False End If
[Code]...
The question is now....how can I unprotect the sheet so that this code works without allowing them to enter data where they shouldn't. I've been at this for days already.
I have a worksheet that is initially protected when a user views it. Certain cells are unlocked. I have 46 drop down lists on the worksheet, of which none are locked so the users can access them for selections. I want to unprotect the sheet when ANY of the dropdowns are clicked on. For each change event I have the following Sub DropDown34_Change()
I've written a little VBScript that generates several hundred Excel 2013 worksheets. In order to protect the users from themselves I protected certain cells. Everything works as expected, except when I discovered that the password I used to protect the worksheet doesn't work to unprotect it. If it matters, I'm not trying to unprotect programmatically, just opening Excel and going that route.
I'm using VB 6.5 and Excel 2007. I've got a workbook that has code that creates another workbook (by copying sheets out of the current workbook) and drops a button on that workbook and creates a macro for that button. Everything works except one thing which gives me
Runtime Error 1004: Unable to update the Caption Property of the Button Class.
If I run the code manually (rather than calling the subroutine from from within another subroutine) it runs without error but if I call it from within the subroutine that copies sheets from the original workbook to a new workbook I get the error. Any idea why this might be? What I might be doing wrong? The code for this subroutine is as follows:
Sub CreateButton() Dim btnMyButton As Button Set btnMyButton = ActiveSheet.Buttons.Add(460, 75, 140, 30) btnMyButton.Caption = "Delete and Update Charts and Lists" End Sub
I have been really trying to get this sorted myself and I can get it to work with one exception. I can't get the sheet to lock with a password. It locks, but if I try to unlock it again, it does so without prompting me to enter a password.
Essentially I am wanting to unprotect two sheets, unlock the cells that were previously locked (so users couldn't enter data in them when the sheet is protected), then reapply the same password to protect the sheet, but now they will be able to enter data in the unlocked range of cells).
The second macro is to reverse the changes made in the first and 're-lock' the unlocked cells) (and again apply the same password to the sheet).
I have a relatively complex report that I work with and a worksheet is no longer required. I have deleted the worksheet and reference to it hwoever when running the macro to pull all the data, it gets to the summary of all the data and i get the Run Time Error 1004 Application-defined or object-defined error pop up. ON reviewing it, it is on this line ActiveCell.Offset(0, 0).Range("a1:a" & Range_Height).Select of the below code...
VB: Sub GetRangeName() Sheets("TOTAL").Select
[Code].....
use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window.
I have a simple function below to put in different forumlas in different cells to get stock quotes. When I run this I get runtime error 1004 application-defined or object-defined error. The first formula goes through but vba chokes on the next formula: ActiveCell.Offset(I - 1, 4).Formula = username
I am trying to copy the info from one workbook to another workbook.
I keep getting the above referenced error...
Private Sub CommandButton1_Click() Dim filepath As String filepath = Range("A100") MsgBox ("File Appended") Workbooks.Open (filepath) Windows("CorrespondenceMaster.xls").Activate Sheets("Sheet2").Select Range("DesNo", "LocationPath").Select Selection.Copy Windows(filepath).Activate Range("A2").Select ActiveSheet.Paste End Sub