Help - Trying to protect form buttons

odonnks

New Member
Joined
Feb 9, 2019
Messages
4
Hello,
I have a macro that works as needed. The sheet has form buttons I want to protect but when I unlock cells A10 to M50 and protect the sheet I receive error 1004 saying a cell its trying to write to is protected and read only.

I'm not sure what I'm missing.

Any help will be appreciated
Thank you



Sub Macro1()
'
' Macro1 Macro
' Clear and upload new cal report
'

'
Range("A10:M50").Select
Selection.ClearContents

'
' Macro1 Macro
' Read text file
'

Dim vFilename As Variant

vFilename = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt), *.txt", _
Title:="Select Text File", _
ButtonText:="Select", _
MultiSelect:=False)

If vFilename = False Then Exit Sub 'user cancelled

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & vFilename, Destination:=Range("$N$10"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(15, 10, 13, 12, 1, 6, 7, 7, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:K").Select
Range("K1").Activate
Selection.Delete Shift:=xlToLeft
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
First you must unprotect, later protect the sheet. Change "abc" for your password.

Code:
Sub Macro1()
'
' Macro1 Macro
' Clear and upload new cal report
'


[COLOR=#0000ff]ActiveSheet.Unprotect "abc"[/COLOR]


Range("A10:M50").Select
Selection.ClearContents


'
' Macro1 Macro
' Read text file
'


Dim vFilename As Variant


vFilename = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt), *.txt", _
Title:="Select Text File", _
ButtonText:="Select", _
MultiSelect:=False)


If vFilename = False Then Exit Sub 'user cancelled


With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & vFilename, Destination:=Range("$N$10"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65001
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(15, 10, 13, 12, 1, 6, 7, 7, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:K").Select
Range("K1").Activate
Selection.Delete Shift:=xlToLeft


[COLOR=#0000ff]ActiveSheet.Protect "abc"[/COLOR]


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,020
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top