form excel file open another excel file and .unprotect that file copy one row and .protect that file and close works only once

lodewijk

New Member
Joined
Nov 8, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I hope you understand the problem Here is the code.
What is wrong. THX

Sub Macro2()
Dim st As String
Dim irow As Long
Workbooks.Open Filename:="C:\Tmp\Dossier.xlsm"
Sheets("Blad1").Activate

Sheets("Blad1").Unprotect Password = "1141"
Sheets("Blad1").Range("A" & Rows.Count).End(xlUp).Offset(1).Activate
Sheets("Blad1").Range("A" & Rows.Count).End(xlUp).Offset(1).Select

' use of this macro a second time it gives an error on next instruction
' but whitout the protect and unprotect it works fine


Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Sheets("Blad1").Protect Password = "1141", userinterfaceonly:=False
ActiveWorkbook.Save
ActiveWindow.Close

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I hope you understand the problem Here is the code.
What is wrong. THX

Sub Macro2()
Dim st As String
Dim irow As Long
Workbooks.Open Filename:="C:\Tmp\Dossier.xlsm"
Sheets("Blad1").Activate

Sheets("Blad1").Unprotect Password = "1141"
Sheets("Blad1").Range("A" & Rows.Count).End(xlUp).Offset(1).Activate
Sheets("Blad1").Range("A" & Rows.Count).End(xlUp).Offset(1).Select

' use of this macro a second time it gives an error on next instruction
' but whitout the protect and unprotect it works fine


Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Sheets("Blad1").Protect Password = "1141", userinterfaceonly:=False
ActiveWorkbook.Save
ActiveWindow.Close

End Sub
I assume that you are wanting to copy this range somewhere but where to?

Sheets("Blad1").Range("A" & Rows.Count).End(xlUp).Offset(1)
 
Upvote 0
I assume that you are wanting to copy this range somewhere but where to?

Sheets("Blad1").Range("A" & Rows.Count).End(xlUp).Offset(1)
I assume that you are wanting to copy this range somewhere but where to?

Sheets("Blad1").Range("A" & Rows.Count).End(xlUp).Offset(1)
sorry maybe I wasn't clear enough. The selected line is copied and then the macro is called, which opens another Excel program and places the copied line in the called file, and then closes the opened excel file.
That works fine if I don't use the protect and unprotect options. When I use the protect options is works once and then the second time in gives an error.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top