?
Solved

Worksheet Protection

Posted on 2004-10-19
8
Medium Priority
?
418 Views
Last Modified: 2010-08-05
From vb 6, I want to send a worksheet to the end and password protect it:

1. Line:    ws.Move after:=Sheets(Worksheets.Count)  errors: method 'Worksheets' of object '_Global' failed.     error: 1004

2. I need code to protect the same worksheet.

3. I need code to unprotect this worksheet to edit its content and then protect it again.

Thanks.




0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
ampapa earned 1200 total points
ID: 12354017
Public Sub test()
Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("ABC")
ws.Move after:=Sheets(Worksheets.Count)

Sheets(Worksheets.Count).Protect Password:="YourPassword"


End Sub

Public Sub unprotect()
Sheets(Worksheets.Count).unprotect Password:="YourPassword"

End Sub


0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12354072
Because we are working from vb 6 not excel environmemt, I have:

Public Sub test()

Dim xlApp As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Set xlApp =GetObject..
Setwb=xlApp.Workbooks(strWb)
Set ws = wb.Worksheets("ABC")

ws.Move after:=Sheets(Worksheets.Count)          <-- this line still produces the error

Sheets(Worksheets.Count).Protect Password:="YourPassword"


End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12354138
Try

ws.Move after:=Sheets(xlApp.Worksheets.Count)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12354181
Erick37,

I will try your solution and reopen the question for a proper split.

Thanks.
0
 
LVL 8

Expert Comment

by:ampapa
ID: 12354256
Sorry, your correct I'm in Excel mode. Erick37 is correct that should fix your problem.
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 800 total points
ID: 12354320
And the other...

ws.Move after:=xlApp.Sheets(xlApp.Worksheets.Count) '<-- Use xlApp to qualify your objects

0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12354856
Thanks Erick,

ws.Move after:=xlApp.Sheets(xlApp.Worksheets.Count)

Works.  Could you opent this question or I need to get assistance from an EE Admin.

Mike
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question