だから私はこのコードが完成したと思っていましたが、シート1から他のシートに移動してからシート1に戻ると、msgboxがポップアップし、保護されていないことを通知しますシート。まだマクロが正常に動作していても、「保護されたシートにこれを行うことはできませんか?
私は、コードが想定していたとおりに正しく動作しているため、なぜこのようなことが起こっているのか不明です。どんな助けもありがとうございます。
編集:私はおそらくシートがパスワード "1"で保護されていると述べたはずです。私はこれが最も適切なパスワードではないことを認識しています。私はこの問題を解決するために、より簡単にアクセスできます。
Sub freezesheet()
'set variable for the naming of the new sheet
Dim newname As String
'assignes our open variable to a designated value
Sheets("Sheet1").Activate
newname = Sheets("Sheet1").Range("C2").Value
'copies the sheet to a new sheet after the designated tab
Sheets("Sheet1").Copy after:=Sheets(3)
ActiveSheet.Name = newname
'unprotects the sheet so we can copy and paste as values
ActiveSheet.Unprotect "1"
'makes all of the formulas on the sheets into values and returns you to the original sheet
Cells.Select
selection.Copy
selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Re-protects sheet to ensure that we don't make changes to historical data.
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True
Sheets("Sheet1").Activate
End Sub
これを2回実行すると、シート名がすでに取得されている場合、シートの名前を「newname」(C2の値)に変更しようとしますか? – Wolfie
良い点、これは既に私がこのツールで扱ってきた問題です。セルC2の値は、マクロを実行する各インスタンスの前にユーザーによって変更されます。 – DataNinja
私は以下の回答を掲載しましたが、あなたの問題点が明白ではありません。これはシート1に戻るときに起こると言っています。このサブはシートチェンジイベントによってトリガーされていますか? – Wolfie