Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

Worksheet Protection

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.




ASKER CERTIFIED SOLUTION
Avatar of ampapa
ampapa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Eghtebas

ASKER

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
Try

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

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

Thanks.
Avatar of ampapa
ampapa

Sorry, your correct I'm in Excel mode. Erick37 is correct that should fix your problem.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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