我有一個工作表從「workbook.protected」複製到新的問題。宏執行如下操作:首先取消保護所需工作表,然後創建新工作簿,將工作表複製到新工作簿,將新工作簿中的所有單元格重新保存爲.values,並保存&關閉工作簿,最後保護父工作簿。 問題在於,由於某些原因,新工作簿不包含值,而是對父工作簿的引用。你能否就這個問題徵求意見? 我使用的代碼如下:VBA Copy Sheet.PROTECTED到新的工作簿ISSUE
Global path As String
Global filename As String
Sub SaveSheet()
Application.ScreenUpdating = False
Dim sh1 As Worksheet
Dim sh2 As Worksheet
On Error Resume Next
Set sh1 = ThisWorkbook.Worksheets("sheet1")
Set sh2 = ThisWorkbook.Worksheets("sheet2")
sh1.Unprotect Password:="password"
sh2.Unprotect Password:="password"
Dim a As String
path = "\\path\"
filename = "file1234"
Set wb = Workbooks.Add
ThisWorkbook.Activate
Sheets("sheet1").Copy Before:=wb.Sheets(1)
ThisWorkbook.Activate
Sheets("sheet2").Copy Before:=wb.Sheets(1)
With wb
Application.DisplayAlerts = False
wb.Activate
Sheets(5).Delete
Sheets(4).Delete
Sheets(3).Delete
Sheets("sheet1").Select
Range("A1:N1000") = Range("A1:N1000").Value
Sheets("sheet2").Select
Range("A1:BW1000") = Range("A1:BW1000").Value
Application.DisplayAlerts = True
End With
ChDir path
With wb
If Len(Dir(path, vbDirectory)) = 0 Then
MkDir path
.SaveAs path & filename & ".xlsb", FileFormat:=50
Else
.SaveAs path & filename & ".xlsb", FileFormat:=50
End If
.Save
.Close
End With
With sh1
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect Password:="password"
End With
With sh2
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect Password:="password"
End With
End Sub
哪來的 「.....代碼」 :) –
這:) Nathan_Sav – Lincoln
範圍( 「A1:N1000」)=範圍( 「A1:N1000」)的價值 - 這是一個非常有趣的。公式的消失方式。它工作嗎?在其他消息中,「Select」和「Activate」可能有所不同。 – Winterknell