Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2015, 10:15 PM
anand anand is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 64bit
Novice
vba code in word to delete line having inline shape
 
Join Date: Jun 2015
Posts: 15
anand is on a distinguished road
Default vba code in word to delete line having inline shape


I am using this type of code .I have to delete entire line which contain image of height and width 24.If I skip "Selection.Rows.Delete" this line then it is deleting all shapes in 2 attempts but give run time error. I am new to VBA . So please suggest me how to correct this code
Sub our()
Dim iShapeCount As Integer
Dim iILShapeCount As Integer
Dim DocThis As Document
Dim J As Integer
Dim K As Integer
Dim sTemp1 As Integer
Dim sTemp2 As Integer
Set DocThis = ActiveDocument




iShapeCount = DocThis.Shapes.Count
For J = 1 To iShapeCount

sTemp1 = DocThis.Shapes(J).Height
sTemp2 = DocThis.Shapes(J).Width
If sTemp1 = 24 And sTemp2 = 24 Then
DocThis.Shapes(J).Delete
Selection.Rows.Delete

End If


Next J



iILShapeCount = DocThis.InlineShapes.Count


For J = 1 To iILShapeCount


sTemp1 = DocThis.InlineShapes(J).Height
sTemp2 = DocThis.InlineShapes(J).Width
If sTemp1 = 24 And sTemp2 = 24 Then

DocThis.InlineShapes(J).Delete
Selection.Rows.Delete


End If



Next J


End Sub
Reply With Quote
  #2  
Old 06-17-2015, 10:52 PM
gmayor's Avatar
gmayor gmayor is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Can you post a sample of the document and indicate what exactly you are trying to do.
Your post mentions 'lines' and code refers to 'rows' without any indication of what they relate to. Removing a shape should be straightforward once we know what exactly you want to remove and what else is in the document that you don't. A sample document will explain far more than your description. Go Advanced to attach a document to the forum.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-17-2015, 11:13 PM
anand anand is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 64bit
Novice
vba code in word to delete line having inline shape
 
Join Date: Jun 2015
Posts: 15
anand is on a distinguished road
Default line example

I have to delete entire line containing this computer and comment symbol.
Attached Files
File Type: docx my1.docx (19.9 KB, 13 views)
Reply With Quote
  #4  
Old 06-18-2015, 02:21 AM
gmayor's Avatar
gmayor gmayor is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

There is no line in the document that contains 'this computer' and comment symbol. Can I assume you mean the line that contains 'Change Notification: Initial Screen' ? In which case

Code:
Sub DeleteRow()
Dim oRng As Range
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute("Change Notification: Initial Screen")
            oRng.Rows(1).Delete
            Exit Do
        Loop
    End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 06-18-2015, 02:43 AM
anand anand is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 32bit
Novice
vba code in word to delete line having inline shape
 
Join Date: Jun 2015
Posts: 15
anand is on a distinguished road
Default deletion

I have to delete this computer shape , comment shape,Change Notification: Initial Screen,In the next steps, the tasks will be set to Complete status.
I need a code that will delete the starting symbol as well as line following it.

In my document there are number of lines that have computer shape and comment shape in starting so i cannot delete it on basis of matching text. Please help me.
Reply With Quote
  #6  
Old 06-18-2015, 04:29 AM
gmayor's Avatar
gmayor gmayor is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Your attached document has four small tables, none of which matches your description and now you tell us that there are more lines (presumaby table rows) that you need to process. As before we need to see the document to see what it is we are dealing with, not just an unrepresentative bit of it.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 06-18-2015, 06:52 AM
anand anand is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 32bit
Novice
vba code in word to delete line having inline shape
 
Join Date: Jun 2015
Posts: 15
anand is on a distinguished road
Default Deletion

This picture clearly shows what i want to do.
I need code to delete all lines that start with this computer symbol and comment symbol.

Last edited by anand; 06-18-2015 at 11:25 PM.
Reply With Quote
  #8  
Old 06-18-2015, 10:02 PM
gmayor's Avatar
gmayor gmayor is offline vba code in word to delete line having inline shape Windows 7 64bit vba code in word to delete line having inline shape Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It gets us a little closer, but the document is bizarrely formatted using assorted tables, with different numbers of columns in the rows. Even on a basic level such tables are difficult to handle.

However, as you originally identified, the only thing you can really hang the code on here is the size of the graphics. If we can assume all the graphics to be removed have the same sizes then the following macro may work, but without the document to test against the results may be unpredictable because of the table format:

Code:
Sub DeleteImages()
Dim oShape As InlineShape
Dim oRng As Range
    For Each oShape In ActiveDocument.InlineShapes
        If oShape.Height = 24 And oShape.Width = 24 Then
            Set oRng = oShape.Range
            oRng.Rows(1).Delete
        End If
    Next oShape
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
vba code in word to delete line having inline shape How to write Text above the Shape Line in Ms Word 2010 tahakirmani Word 2 11-28-2013 05:33 PM
Adapting a line shape NikkiB Word 4 03-18-2013 08:45 AM
Find/Delete inline Page #'s alderfall Word 6 11-06-2012 11:51 AM
How do i get my text in columns straight and inline in word 2007? terrasaw Word 0 09-03-2008 06:00 AM
Delete excel files by code in Access Barry Richardson Office 0 06-13-2005 06:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:49 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft