Protect worksheet after running VBA code for converting column to text

Excel_Learner29

New Member
Joined
Apr 1, 2019
Messages
5
Hi, i am trying to unprotect my worksheet to run below code for converting columns into text and then protect sheet again but somehow its not working.

Please help!

Sub EWEB2()
Dim ws As Worksheet
Set ws = Worksheets("EWEB")
ws.Select
ws.Unprotect Password:="dim"
Columns("G:G").Select
Selection.TextToColumns Destination:=Range("G1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
ws.Protect Password:="dim", DrawingObjects:=True, contents:=True, Scenarios:=True, AllowFiltering:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, UserInterFaceOnly:=True
End Sub
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,303
Office Version
2013
Platform
Windows
Re: how to Protect worksheet after running VBA code for converting column to text

Maybe this

Code:
Sub EWEB2()
Dim ws As Worksheet
Set ws = Worksheets("EWEB")
With ws
.Unprotect Password:="dim"
.Columns("G:G").TextToColumns Destination:=Range("G1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
.Protect Password:="dim", DrawingObjects:=True, contents:=True, Scenarios:=True, AllowFiltering:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, UserInterFaceOnly:=True
End With
End Sub
 

Forum statistics

Threads
1,085,496
Messages
5,384,000
Members
401,871
Latest member
allemandi

Some videos you may like

This Week's Hot Topics

Top