Solved

Worksheet Protection

Posted on 2004-10-19
8
393 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
  • 3
  • 2
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
ampapa earned 300 total points
Comment Utility
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 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
Comment Utility
Try

ws.Move after:=Sheets(xlApp.Worksheets.Count)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Erick37,

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

Thanks.
0
 
LVL 8

Expert Comment

by:ampapa
Comment Utility
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
Comment Utility
And the other...

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

0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now