ユーザーが変更できる別のブックを作成するExcelマクロがあります。しかし、新しいワークブックのセルにデータを入力しようとすると、「変更しようとしているセルまたはチャートが保護されたシートにあります」というエラーが表示されます。実際、マクロブックのシートは保護されていますが、エラーが発生した時点でそのシートは表示されません。目に見えて新しく作成されたブックを閉じると、それは閉じるマクロブックです。マクロが最後に行うことは、新しいブックのシートをアクティブにすることです。私はその仕事をするために何をしなければなりませんか?マクロを閉じて独自のワークブックを作成すると、問題は解決しますが、ユーザーが新しいシートの変更を処理するために同じブック内の別のマクロを必要とするため、これはやりたいことではありません。Excel 2016:アクティブなワークシートは表示されていません
プログラムには6000行以上のコードがありますが、ここで問題の原因となっているルーチンの1つです。
Private Sub z3_BudgetPrepUpd()
'Build a new workbook initialized to let the user modify data
'for an existing fiscal-quarter budget.
'When this routine executes,
' UserForm1 is still active.
Dim strTracer As String 'error-handling tracer for this subroutine
Dim strFyrQtr As String
On Error GoTo abend
If blnAbort Then Exit Sub
If blnAbortGlobal Then Exit Sub
'Find out which ListBox item the user selected:
If UserForm1.ListBox1.ListCount < 1 Then GoTo aa9000 'ListBox is empty
If UserForm1.ListBox1.ListIndex < 0 Then 'No item selected
strMsgTitle = udtPrm.msgTtl
strMsgPrompt = "Please select a fiscal quarter to update."
Call z0_MsgBox
GoTo aa9000
End If
strFyrQtr = UserForm1.ListBox1.Value 'Selected item in ListBox
'Close UserForm1:
UserForm1.Hide
ThisWorkbook.Sheets(c_WKS_WELCOME).Activate
'Build the udtBgt() array with data for the specified quarter:
lngBgtHiNdx = -1
Call zz_GetBudgetForQtr(strFyrQtr)
If blnAbort Then GoTo aa9000
'Build a new workbook for the user to update budget amounts:
Workbooks.Add
Set wkbNewBook = ActiveWorkbook
'Save the names of the default worksheets
'so we can delete them later:
strDfltSheets() = z0_SheetNames(wkbNewBook)
'Build a worksheet with data from the udtBgt() array:
Call z3_BuildBudgetUpdSheet
If blnAbort Then GoTo aa9000
'Delete the default worksheets:
Call z0_DeleteSheets(wkbNewBook, strDfltSheets())
If blnAbort Then GoTo aa9000
wkbNewBook.Sheets(c_WKS_IPT_BUDGET).Activate
'Excel 2016 Bug:
'We need to close ThisWorkbook to allow the user
'to work with the book we just created:
Application.DisplayAlerts = False
ThisWorkbook.Close
aa9000:
Exit Sub
abend:
lngErr = Err.Number
strErr = Err.Description
blnAbort = True
Application.Cursor = xlDefault 'no more hourglass
strMsgTitle = "Program Error"
strMsgPrompt = "The following error occurred:" & Chr(10) & Chr(10) & _
"Error No. " & CStr(lngErr) & Chr(10) & _
"Error Description: " & strErr & Chr(10) & _
"Subroutine: z3_BudgetPrepUpd" & Chr(10) & _
"Tracer: " & strTracer
Call z0_MsgBox
Resume aa9000
End Sub
もし私がurコードを表示すると、問題を特定するのがより簡単になる – Rosetta
問題ルーチンからコードを追加しましたが、どれくらい役立つか分かりません。ありがとう。 –
エラーはどの回線で発生しますか?船の修正をお願いします。 –