excel vba - Excel में एकाधिक पत्रक पर जोड़ें
excel-vba comments (4)
Addcomment वाक्यविन्यास कार्यपुस्तिका में पहली चयनित शीट पर काम करता है, लेकिन अगले एक के लिए मुझे यह त्रुटि मिलती है: 1004 त्रुटि "अनुप्रयोग परिभाषित या ऑब्जेक्ट-परिभाषित त्रुटि"। मैं नहीं जानता कि यदि एकाधिक शीट चुने गए तो क्रैश क्यों हुआ और केवल पहले चयनित एक के लिए काम करता है क्या किसी को कुछ विचार है?
If selectedSheet.Cells(7, columnIndex).value <> 100 Then
selectedSheet.Cells(7, columnIndex).Interior.ColorIndex = 3
If standardReportFilePath <> "" Then 'not using the Standard Report Evalution algorithm
If VerifyStandardReportFile(selectedSheet.Name, selectedSheet.Cells(1, columnIndex).value, wbk, amplitude, missingCrashes) = True Then
selectedSheet.Cells(1, columnIndex).Interior.ColorIndex = 36 ' color the crash cell with yellow
Set rng = selectedSheet.Cells(1, columnIndex)
If rng.Comment Is Nothing Then
**rng.AddComment "In Standard Report this crash starts to deploy from " & CStr(amplitude) & " amplitude"**
Else
rng.Comment.Text "In Standard Report this crash starts to deploy from " & CStr(amplitude) & " amplitude"
End If
End If
End If
End If
End If
कोड का एक वैकल्पिक समूह जो समस्या दिखाता है। (इसे एक नई कार्यपुस्तिका में तीन रिक्त कार्यपत्रकों के साथ चलाएं।):
Sub test()
Dim ws As Worksheet
Dim Rng As Range
'Running code with a single sheet selected
Worksheets("Sheet1").Select
'Code that shows issue - this will work
Set ws = Worksheets("Sheet2")
Set Rng = ws.Cells(1, 1)
If Rng.Comment Is Nothing Then
Rng.AddComment "xxx"
End If
'Get rid of comment again
Rng.Comment.Delete
'Running code with multiple sheets selected
Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
'Code that shows issue - will crash on the "AddComment"
Set ws = Worksheets("Sheet2")
Set Rng = ws.Cells(1, 1)
If Rng.Comment Is Nothing Then
Rng.AddComment "xxx"
End If
End Sub
मुझे आम तौर पर ऐसा ही मामला याद है (मैं कोड से कुछ नहीं कर सकता), इसे हल करने की कोशिश कर रहा था और आखिरकार मैंने पाया ...
ध्यान दें कि अगर आपके पास एकाधिक शीट चयनित हैं, तो रिबन पर "नई टिप्पणी" बटन निष्क्रिय है , इसलिए आप इसे कोड से नहीं कर सकते हैं यदि आप इसे मैन्युअल रूप से नहीं कर सकते हैं
क्यूं कर? - मुझसे मत पूछो मैं ऊपर एक अच्छा कामकाज देख रहा हूं, जो आपको वही जरूरतों को प्राप्त करने का एकमात्र तरीका है।
मुझे एक वैकल्पिक हल मिल गया, लेकिन फिर भी यह नहीं पता कि यह समस्या तब भी क्यों होती है। किसी कारण के लिए त्रुटि तब होती है जब आपके पास एक वर्कशीट चयनित हो। समाधान है ... कुछ शीट के साथ टिप्पणी जोड़ने से पहले एक शीट का चयन करें। चयन करें मैक्रो के अंत में आप अगर आवश्यक हो तो फिर से सभी पहले चयनित शीट का चयन करने का प्रयास कर सकते हैं
मैं क्या समझता हूं - Yoweks टिप्पणी के लिए धन्यवाद - है: आप सभी चयनित शीट्स के माध्यम से पाशन कर रहे हैं, कुछ की जांच करें, टिप्पणी सेट करें (आपको समस्याएं दे रहा है, क्योंकि यह एक से अधिक चयनित शीट के साथ काम नहीं करता है) और पूर्वव्यापी रूप से चयनित बाद में चयन करने वाली चादरें
आप एक चर में पूर्वव्यापी चयनित पत्र को सहेज सकते हैं, उनमें से एक का चयन कर सकते हैं, अपना कोड चला सकते हैं और फिर सभी पूर्वव्यापी चयनित पत्रक का चयन कर सकते हैं। निम्नलिखित कोड का प्रयास करें:
Sub Comments()
Dim WsArr As Sheets, WS As Worksheet, ColIdx As Long
ColIdx = 7
Set WsArr = ActiveWorkbook.Windows(1).SelectedSheets
WsArr(1).Select
For Each WS In WsArr
'*** your logic
Set Rng = WS.Cells(1, ColIdx)
If Rng.Comment Is Nothing Then
Rng.AddComment "In Standard Report this crash starts to deploy from " & CStr(amplitude) & " amplitude"
Else
Rng.Comment.Text "Changed T"
End If
Next WS
WsArr.Select
End Sub
टिप्पणियों का उपयोग करके आप व्यक्तिगत कोशिकाओं में नोट जोड़ सकते हैं
आप एक्सेल में 'समीक्षा' टैब में देख सकते हैं, जब आप कई शीट्स का चयन करते हैं, तो आप कोई टिप्पणी नहीं बना सकते मुझे लगता है कि ऐसा करने के लिए एक्सेल के इंटरनल के साथ क्या करना है, यह निर्धारित करने के लिए कि किस कक्ष में एक टिप्पणी को असाइन किया जाना चाहिए।
यहां एक ऐसा समारोह है, जिसे आप किसी दिए गए सेल पर एक टिप्पणी देने के लिए कॉल कर सकते हैं, भले ही आपके पास एकाधिक शीट चयनित हों
यह उप भी एक टिप्पणी पहले से मौजूद है अगर परीक्षण करने की आवश्यकता को हटा देता है , बस उस कक्ष में एक नई टिप्पणी दें जो पहले से ही एक है
Sub UpdateComment(Rng As Range, Cmnt As String)
Application.ScreenUpdating = False
' Get currently selected sheets
Dim mySheets As Sheets: Set mySheets = ThisWorkbook.Windows(1).SelectedSheets
' Set current selection to just one sheet: this is where error is avoided
ThisWorkbook.Sheets(1).Select
' Set Comment, new if doesn't exist or changed if it does
If Rng.Comment Is Nothing Then
Rng.AddComment Cmnt
Else
Rng.Comment.Text Cmnt
End If
' Tidy up: re-select sheets & enable screen updating
mySheets.Select
Application.ScreenUpdating = True
End Sub
इसे अपने कोड में ऐसा प्रयोग करें:
' ... your previous code
Set rng = selectedSheet.Cells(1, columnIndex)
UpdateComment rng, "In standard report this crash starts to deploy from ..."
सभी चयनित शीट्स पर लूप के लिए
Dim sh As Worksheet
For Each sh In ThisWorkbook.Windows(1).SelectedSheets
Set rng = sh.Cells(1, columnIndex)
UpdateComment rng, "In standard report this crash starts to deploy from ..."
Next sh