Solved

Worksheet Protection

Posted on 2004-10-19
8
399 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 300 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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