LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Unprotect and protect sheet in a macro

Hello

When I run this macro half the time I get a fault in the paste special line,
The worksheet I paste into is protected (no password) so in the beginning I
unprotect it and in the end I protect it. It says the pastespecial method
is not working. Help me please, it drives me nuts. If the sheet is not
protected in the beginning all is working fine.

Sub kopiera()

Application.ScreenUpdating = False
Sheets("Faktura").Activate
Range("J5").Select
Selection.Copy
Workbooks.Open Filename:="C:\Excelprojekt/Faktura Åkeri\Reskontra1.xls"
Windows("Reskontra1.xls").Activate
Sheets("Reskontra").Activate
Sheets("Reskontra").Unprotect
Columns("A:A").Select
Selection.FindNext(After:=ActiveCell).Activate
ActiveCell.Offset(0, 0).Range("a1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
_
False, Transpose:=False

Windows("Faktura.xls").Activate
Sheets("Faktura").Activate
Range("G5").Select
Selection.Copy
Windows("Reskontra1.xls").Activate
Sheets("Reskontra").Activate
Columns("B:B").Select
Selection.FindNext(After:=ActiveCell).Activate
ActiveCell.Offset(0, 0).Range("a1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
_
False, Transpose:=False
Sheets("Reskontra").Protect
ActiveWorkbook.Save
ActiveWindow.Close



ActiveWorkbook.SaveAs Filename:="c:\Excelprojekt/Faktura
Åkeri\Fakturor\" & Range("G5") - 1 & "xls", FileFormat:=xlNormal,
Password:="", WriteResPassword:="", ReadOnlyRecommended:=True,
CreateBackup:=False

Sheets("Faktura").Select
Range("A21:B36").Select
Selection.ClearContents
Range("H5").Select
Selection.ClearContents
Range("H21:I36").Select
Selection.ClearContents

Range("A21").Select

Application.ScreenUpdating = True

ActiveWorkbook.SaveAs Filename:="C:\Excelprojekt/Faktura
Åkeri\Faktura.xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False

Application.Quit

End Sub

TIA

Ola Sigurdh


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to protect/unprotect a sheet using a macro with password FredH Excel Discussion (Misc queries) 5 October 23rd 07 04:49 PM
Protect/Unprotect Sheet from Macro Nigel[_8_] Excel Programming 1 May 14th 04 05:55 PM
Excel VBA-Protect and unprotect sheet with BVA marfrk Excel Programming 1 May 3rd 04 12:37 PM
Protect/unprotect sheet with password with VBA? dragontale[_7_] Excel Programming 1 April 19th 04 09:29 PM
VBA code - protect and unprotect a sheet Jeff Excel Programming 2 December 2nd 03 11:44 PM


All times are GMT +1. The time now is 02:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"