Make a code work for only active sheet, not all sheets.

Make a code work for only active sheet, not all sheets.

Anonymous
Not applicable
693 Views
3 Replies
Message 1 of 4

Make a code work for only active sheet, not all sheets.

Anonymous
Not applicable

Hi. I have 2 codes. They work beautifully, however they work on all sheets and I just want them to work on the active sheet. Someone who can help me edit the codes?

 

Code 1 (Delete Scale)

For Each oSheet As Sheet In ThisDrawing.Document.Sheets
	For Each oView As DrawingView In oSheet.DrawingViews
		oView.Label.FormattedText = oView.Label.FormattedText.Replace("<DrawingViewScale/>", "").Replace("(", "").Replace(")", "")
	Next
Next

 

Code 2 (Delete Border)

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveEditDocument

Dim oCurrentNumber  As Sheet
oCurrentNumber = oDoc.ActiveSheet

' Iterate through the sheets, and delete the title blocks and symbols
Dim oSheet As Sheet
For Each oSheet In oDoc.Sheets
    oSheet.Activate
    
    Try
    oSheet.Border.Delete
    Catch
    'catch error if no border found
    End Try
    

Next
0 Likes
Accepted solutions (3)
694 Views
3 Replies
Replies (3)
Message 2 of 4

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Seems like this should do it?

Rule 1:

For Each oView As DrawingView In ActiveSheet.Sheet.DrawingViews
	oView.Label.FormattedText = oView.Label.FormattedText.Replace("<DrawingViewScale/>", "").Replace("(", "").Replace(")", "")
Next

Rule 2:

Try
ActiveSheet.Sheet.Border.Delete
Catch
End Try
Message 3 of 4

Martin-Winkler-Consulting
Advisor
Advisor
Accepted solution

@Anonymous 

This should work:

'Code1
Sub DeleteScale()
 Dim oDoc As DrawingDocument
 oDoc = ThisApplication.ActiveEditDocument
 Dim oActiveSheet As Sheet
 oActiveSheet = oDoc.ActiveSheet
	For Each oView As DrawingView In oActiveSheet.DrawingViews
		oView.Label.FormattedText = oView.Label.FormattedText.Replace("<DrawingViewScale/>", "").Replace("(", "").Replace(")", "")
	Next
End Sub


'Code2
Sub DeleteBorder()
 Dim oDoc As DrawingDocument
 oDoc = ThisApplication.ActiveEditDocument
 Dim oActiveSheet  As Sheet
 oActiveSheet = oDoc.ActiveSheet
	Try
     oActiveSheet.Border.Delete
    Catch
    'catch error if no border found
    End Try
End Sub
  

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

Message 4 of 4

Anonymous
Not applicable
Accepted solution

Perfect! Thank you both. Appreciate your help!

0 Likes