Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Worksheet Protection

Posted on 2004-10-19
8
Medium Priority
?
430 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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