Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2017, 03:31 PM
romanticbiro romanticbiro is offline handle textbox, pictures, and all kind of shapes Windows 7 32bit handle textbox, pictures, and all kind of shapes Office 2003
Advanced Beginner
handle textbox, pictures, and all kind of shapes
 
Join Date: Feb 2014
Posts: 42
romanticbiro is on a distinguished road
Question handle textbox, pictures, and all kind of shapes

hello dears



i found this macro which remove textbox and rewrite its content in body text,
but i need to develope it more to make the same in opictures or other shapes
(sometimes people put picture in word and type text on it and this make problem for me)

Code:
Sub RemoveTextBox2()
    Dim shp As Shape
    Dim oRngAnchor As Range
    Dim sString As String
    For Each shp In ActiveDocument.Shapes
        If shp.Type = msoTextBox Then
            ' copy text to string, without last paragraph mark
            sString = Left(shp.TextFrame.TextRange.Text, _
              shp.TextFrame.TextRange.Characters.Count - 1)
            If Len(sString) > 0 Then
                ' set the range to insert the text
                Set oRngAnchor = shp.Anchor.Paragraphs(1).Range
                ' insert the textbox text before the range object
                oRngAnchor.InsertBefore _
                  "Textbox start << " & sString & " >> Textbox end"
            End If
            shp.delete
        End If
    Next shp
End Sub
please help me if you have another idea.
thanks

Last edited by macropod; 02-24-2017 at 08:21 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 02-24-2017, 08:21 PM
macropod's Avatar
macropod macropod is offline handle textbox, pictures, and all kind of shapes Windows 7 64bit handle textbox, pictures, and all kind of shapes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Shp As Shape, Rng As Range
With ActiveDocument
  For Each Shp In .Shapes
    With Shp
      If Not .TextFrame Is Nothing Then
        If Len(Trim(.TextFrame.TextRange.Text)) > 1 Then
          Set Rng = .Anchor
          With Rng
            .InsertBefore "Textbox start << "
            .Collapse wdCollapseEnd
            .InsertAfter " >> Textbox end"
            .Collapse wdCollapseStart
          End With
          Rng.FormattedText = .TextFrame.TextRange.FormattedText
        End If
        .Delete
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-27-2017, 04:21 AM
romanticbiro romanticbiro is offline handle textbox, pictures, and all kind of shapes Windows 7 32bit handle textbox, pictures, and all kind of shapes Office 2003
Advanced Beginner
handle textbox, pictures, and all kind of shapes
 
Join Date: Feb 2014
Posts: 42
romanticbiro is on a distinguished road
Talking

hello macropod

thanks for your help,
is this code will work only on office 2010?
also i notice from code it will insert text only from textbox,
and what i need to retype text from all word arts (textbox, ppicture, autoshapes ...etc), also removing any background picture.

thanks very much.
Reply With Quote
  #4  
Old 02-27-2017, 05:23 AM
macropod's Avatar
macropod macropod is offline handle textbox, pictures, and all kind of shapes Windows 7 64bit handle textbox, pictures, and all kind of shapes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code works in all Word versions. If the text is part of an image, it is no longer text, but pixels in an image; in that case, you need OCR software, not a macro.

Since the code you posted only concerned textboxes that were shape objects, that is what I showed you how to extend; you did not mention the need to process inlineshapes. The mere fact the code reports all the extracts as being from textboxes is inconsequential; outputting each & every shape type as well would require considerably more code - there are 24 different shape types.

WordArt is normally not a Shape object but an InlineShape object; if you want to extract such text, you need to process InlineShape objects as well. I suggest you have a go at that - it's not a major undertaking.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-27-2017, 06:00 AM
romanticbiro romanticbiro is offline handle textbox, pictures, and all kind of shapes Windows 7 32bit handle textbox, pictures, and all kind of shapes Office 2003
Advanced Beginner
handle textbox, pictures, and all kind of shapes
 
Join Date: Feb 2014
Posts: 42
romanticbiro is on a distinguished road
Default

hello macropod

am sorry for any mesunderstod, i'm visually impaired so i not use such objects normal / inline shapes
just i want to remove all shapes inline / normal without lose its text,
sure i know the different between text inside image which need ocr and text which written above these objects in word file.
also, i tried your code in a document contains textbox and other shapes it not extract text from textbox or delete them for this asked you about office version.

now hope you help me in this macro or guide me to handel it by myself if you not have time.

again thanks very much for your efforts with me.
Reply With Quote
  #6  
Old 02-27-2017, 06:20 AM
macropod's Avatar
macropod macropod is offline handle textbox, pictures, and all kind of shapes Windows 7 64bit handle textbox, pictures, and all kind of shapes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range, StrType
With ActiveDocument
  For i = .Shapes.Count To 1 Step -1
    With .Shapes(i)
      If Not .TextFrame Is Nothing Then
        Select Case .Type
          Case msoAutoShape: StrType = "AutoShape"
          Case msoCallout: StrType = "Callout"
          Case msoCanvas: StrType = "Canvas"
          Case msoChart: StrType = "Chart"
          Case msoComment: StrType = "Comment"
          Case msoDiagram: StrType = "Diagram"
          Case msoEmbeddedOLEObject: StrType = "EmbeddedOLEObject"
          Case msoFormControl: StrType = "FormControl"
          Case msoFreeform: StrType = "Freeform"
          Case msoGroup: StrType = "Group"
          Case msoInk: StrType = "Ink"
          Case msoInkComment: StrType = "InkComment"
          Case msoLine: StrType = "Line"
          Case msoLinkedOLEObject: StrType = "LinkedOLEObject"
          Case msoLinkedPicture: StrType = "LinkedPicture"
          Case msoMedia: StrType = "Media"
          Case msoOLEControlObject: StrType = "OLEControlObject"
          Case msoPicture: StrType = "Picture"
          Case msoPlaceholder: StrType = "Placeholder"
          Case msoScriptAnchor: StrType = "ScriptAnchor"
          Case msoShapeTypeMixed: StrType = "ShapeTypeMixed"
          Case msoTable: StrType = "Table"
          Case msoTextBox: StrType = "TextBox"
          Case msoTextEffect: StrType = "TextEffect"
        End Select
        If Len(Trim(.TextFrame.TextRange.Text)) > 1 Then
          Set Rng = .Anchor
          With Rng
            .InsertBefore StrType & " start << "
            .Collapse wdCollapseEnd
            .InsertAfter " >> end " & StrType
            .Collapse wdCollapseStart
          End With
          Rng.FormattedText = .TextFrame.TextRange.FormattedText
        End If
        .Delete
      End If
    End With
  Next
  For i = .InlineShapes.Count To 1 Step -1
    With .InlineShapes(i)
      If Not .TextEffect Is Nothing Then
        If Len(Trim(.TextEffect.Text)) > 1 Then
          Select Case .Type
            Case wdInlineShapeChart: StrType = "InlineChart"
            Case wdInlineShapeDiagram: StrType = "InlineDiagram"
            Case wdInlineShapeEmbeddedOLEObject: StrType = "InlineEmbeddedOLEObject"
            Case wdInlineShapeHorizontalLine: StrType = "InlineHorizontalLine"
            Case wdInlineShapeLinkedOLEObject: StrType = "InlineLinkedOLEObject"
            Case wdInlineShapeLinkedPicture: StrType = "InlineLinkedPicture"
            Case wdInlineShapeLinkedPictureHorizontalLine: StrType = "InlineShapeLinkedPictureHorizontalLine"
            Case wdInlineShapeLockedCanvas: StrType = "InlineLockedCanvas"
            Case wdInlineShapeOLEControlObject: StrType = "InlineOLEControlObject"
            Case wdInlineShapeOWSAnchor: StrType = "InlineOWSAnchor"
            Case wdInlineShapePicture: StrType = "InlinePicture"
            Case wdInlineShapePictureBullet: StrType = "InlinePictureBullet"
            Case wdInlineShapePictureHorizontalLine: StrType = "InlinePictureHorizontalLine"
            Case msoLinkedOLEObject: StrType = "LinkedOLEObject"
            Case wdInlineShapeScriptAnchor: StrType = "InlineScriptAnchor"
          End Select
          Set Rng = .Range
          With Rng
            .Collapse wdCollapseStart
            .InsertBefore StrType & " start << "
            .Collapse wdCollapseEnd
            .InsertAfter " >> end " & StrType
            .Collapse wdCollapseStart
          End With
          Rng.Text = .TextEffect.Text
        End If
        .Delete
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
PS: You will never learn much VBA by simply having others do the coding work for you. Furthermore, I note that you have never thanked anyone here for all the help you've been given. In future, don't take the help for granted and expect to show you've made a decent effort yourself before asking for help! I, for one, am getting tired of providing help to someone who doesn't always state the problem clearly, makes no apparent effort to solve the problem for themselves and then shows no gratitude for the work done...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 02-27-2017, 08:03 AM
romanticbiro romanticbiro is offline handle textbox, pictures, and all kind of shapes Windows 7 32bit handle textbox, pictures, and all kind of shapes Office 2003
Advanced Beginner
handle textbox, pictures, and all kind of shapes
 
Join Date: Feb 2014
Posts: 42
romanticbiro is on a distinguished road
Default

dear macropod

kindly note that not all forum feature accessible for me with screen reader

i not able to use add reputation.
but for sure you and others in this forum help me more.
am so sorry sir if i not able to show my thanks in ur profile.
Reply With Quote
  #8  
Old 02-27-2017, 11:55 AM
romanticbiro romanticbiro is offline handle textbox, pictures, and all kind of shapes Windows 7 32bit handle textbox, pictures, and all kind of shapes Office 2003
Advanced Beginner
handle textbox, pictures, and all kind of shapes
 
Join Date: Feb 2014
Posts: 42
romanticbiro is on a distinguished road
Default

dear macropod

again thanks for your efforts
in your code it gave me errowr in compiling "sub or function not defined" and i able to fix it
the problem was in this line: With InlineShapes(i)
i fixed to: With .InlineShapes(i)
but i found runtime errowr when use macro in a document erowr 5917
and am try to fix it,
If Len(Trim(.TextFrame.TextRange.Text)) > 1 Then

wish help me in this
and i'll try it on another ofice version.

many thanks for your advice.

Last edited by romanticbiro; 02-27-2017 at 03:25 PM. Reason: correcting reply
Reply With Quote
  #9  
Old 02-27-2017, 07:32 PM
macropod's Avatar
macropod macropod is offline handle textbox, pictures, and all kind of shapes Windows 7 64bit handle textbox, pictures, and all kind of shapes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Since the expression:
If Len(Trim(.TextFrame.TextRange.Text)) > 1 Then
is unchanged from the previous working version of the macro, I can't see why you'd get a error 5917 unless you changed something else in the code. What is the error message and what does StrType contain at that point?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 03-01-2017, 01:14 PM
romanticbiro romanticbiro is offline handle textbox, pictures, and all kind of shapes Windows 7 32bit handle textbox, pictures, and all kind of shapes Office 2003
Advanced Beginner
handle textbox, pictures, and all kind of shapes
 
Join Date: Feb 2014
Posts: 42
romanticbiro is on a distinguished road
Default

dear macropod

run time errowr 5917 (this object does not support attached text)

this happenned with all shapes strType but work only with textbox & inlineShapes

also i tried to convert shapes to inlineShapes cause it give me better result but not success
i used .convertToInlineShape
in general or even tried with msoPicture
both failed

but i able to do it throw my program not macro,

so at least if possible need solution to this 5917 errowr in line
if len(trim ...

thanks
Reply With Quote
  #11  
Old 03-01-2017, 11:57 PM
macropod's Avatar
macropod macropod is offline handle textbox, pictures, and all kind of shapes Windows 7 64bit handle textbox, pictures, and all kind of shapes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, Rng As Range, StrType
With ActiveDocument
  For i = .Shapes.Count To 1 Step -1
    With .Shapes(i)
      If Not .TextFrame Is Nothing Then
        On Error GoTo SkipShp
        If Len(Trim(.TextFrame.TextRange.Text)) > 1 Then
          Select Case .Type
            Case msoAutoShape: StrType = "AutoShape"
            Case msoCallout: StrType = "Callout"
            Case msoCanvas: StrType = "Canvas"
            Case msoChart: StrType = "Chart"
            Case msoComment: StrType = "Comment"
            Case msoDiagram: StrType = "Diagram"
            Case msoEmbeddedOLEObject: StrType = "EmbeddedOLEObject"
            Case msoFormControl: StrType = "FormControl"
            Case msoFreeform: StrType = "Freeform"
            Case msoGroup: StrType = "Group"
            Case msoInk: StrType = "Ink"
            Case msoInkComment: StrType = "InkComment"
            Case msoLine: StrType = "Line"
            Case msoLinkedOLEObject: StrType = "LinkedOLEObject"
            Case msoLinkedPicture: StrType = "LinkedPicture"
            Case msoMedia: StrType = "Media"
            Case msoOLEControlObject: StrType = "OLEControlObject"
            Case msoPicture: StrType = "Picture"
            Case msoPlaceholder: StrType = "Placeholder"
            Case msoScriptAnchor: StrType = "ScriptAnchor"
            Case msoShapeTypeMixed: StrType = "ShapeTypeMixed"
            Case msoTable: StrType = "Table"
            Case msoTextBox: StrType = "TextBox"
            Case msoTextEffect: StrType = "TextEffect"
          End Select
          Set Rng = .Anchor
          With Rng
            .InsertBefore StrType & " start << "
            .Collapse wdCollapseEnd
            .InsertAfter " >> end " & StrType
            .Collapse wdCollapseStart
          End With
          Rng.FormattedText = .TextFrame.TextRange.FormattedText
          .Delete
        End If
SkipShp:
        On Error GoTo 0
      End If
    End With
  Next
  For i = .InlineShapes.Count To 1 Step -1
    With .InlineShapes(i)
      If Not .TextEffect Is Nothing Then
        On Error GoTo SkipiShp
        If Len(Trim(.TextEffect.Text)) > 1 Then
          Select Case .Type
            Case wdInlineShapeChart: StrType = "InlineChart"
            Case wdInlineShapeDiagram: StrType = "InlineDiagram"
            Case wdInlineShapeEmbeddedOLEObject: StrType = "InlineEmbeddedOLEObject"
            Case wdInlineShapeHorizontalLine: StrType = "InlineHorizontalLine"
            Case wdInlineShapeLinkedOLEObject: StrType = "InlineLinkedOLEObject"
            Case wdInlineShapeLinkedPicture: StrType = "InlineLinkedPicture"
            Case wdInlineShapeLinkedPictureHorizontalLine: StrType = "InlineShapeLinkedPictureHorizontalLine"
            Case wdInlineShapeLockedCanvas: StrType = "InlineLockedCanvas"
            Case wdInlineShapeOLEControlObject: StrType = "InlineOLEControlObject"
            Case wdInlineShapeOWSAnchor: StrType = "InlineOWSAnchor"
            Case wdInlineShapePicture: StrType = "InlinePicture"
            Case wdInlineShapePictureBullet: StrType = "InlinePictureBullet"
            Case wdInlineShapePictureHorizontalLine: StrType = "InlinePictureHorizontalLine"
            Case msoLinkedOLEObject: StrType = "LinkedOLEObject"
            Case wdInlineShapeScriptAnchor: StrType = "InlineScriptAnchor"
          End Select
          Set Rng = .Range
          With Rng
            .Collapse wdCollapseStart
            .InsertBefore StrType & " start << "
            .Collapse wdCollapseEnd
            .InsertAfter " >> end " & StrType
            .Collapse wdCollapseStart
          End With
          Rng.Text = .TextEffect.Text
          .Delete
        End If
SkipiShp:
        On Error GoTo 0
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 03-02-2017, 05:29 AM
romanticbiro romanticbiro is offline handle textbox, pictures, and all kind of shapes Windows 7 32bit handle textbox, pictures, and all kind of shapes Office 2003
Advanced Beginner
handle textbox, pictures, and all kind of shapes
 
Join Date: Feb 2014
Posts: 42
romanticbiro is on a distinguished road
Default

evening macropod

unfortionatly the errowr 5917 still the same

before i write to you i tried some solution to solve this problem
this line do the trick
if .textframe.has text then
if len(trim ...

but the problem now with it it process only shapes which support text and leave others like (lines, groups, freeforms .. etc) in a document
next part of macro which process inlineShapes works without errowrs even without use your last modification.


fore sure practice let me learn more, thanks for support.
Reply With Quote
  #13  
Old 03-02-2017, 02:37 PM
macropod's Avatar
macropod macropod is offline handle textbox, pictures, and all kind of shapes Windows 7 64bit handle textbox, pictures, and all kind of shapes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by romanticbiro View Post
unfortionatly the errowr 5917 still the same
I can't see how that can be so when you say:
Quote:
Originally Posted by romanticbiro View Post
but the problem now with it it process only shapes which support text and leave others like (lines, groups, freeforms .. etc) in a document
What shapes are still causing 5917 errors? And, if a shape or inlineshape has no text, what do you expect to be done with it?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
What are the minimum margins most printers can handle? 20GT Word 3 11-08-2014 10:40 PM
handle textbox, pictures, and all kind of shapes Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM
handle textbox, pictures, and all kind of shapes Shapes don't have green handle rdy4trvl Drawing and Graphics 4 05-15-2012 09:53 PM
handle textbox, pictures, and all kind of shapes How does Powerpoint handle resolution of images? noni PowerPoint 2 08-09-2010 03:32 PM
How to handle resources that have Bid on project rrmccabe Project 0 03-21-2010 12:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:09 PM.


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