none
VBA Cut Data from Textframe and past outside it (MS Word 2013) Problem RRS feed

  • Question

  •    

    Hi there, i m working in word vba (office 2013), i want to cut data from inside textframe or textbox to paste outside the textframe 
    i used following code to do such operation, but it works on new files, where i cut paste textframes from old files or saved files,
     and do not work on real file where textframes are naturally placed by user, i cant understand where is problem and what is diffrence between these files and how to solve

     please help me find the problem that why does it not work on real file where textframes are places along with other text

    it shows error

    run time error 5917
    the object does not support attached text



    Sub fromtxtbox()
    
    For Each s In ActiveDocument.Shapes
     Selection.Collapse WdCollapseDirection.wdCollapseEnd
    
    s.TextFrame.TextRange.Cut
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        
      
    Next
    end sub




    this run fine on some files and not on some files also

    yes i want to place cut data accurate on same place where textframe is placed and want to delete empty textframes after cut past operation, plz also help with these codings

    Friday, March 3, 2017 11:36 AM

All replies

  • Hi Fahad,

    Based on your description, it seems to be related with your files. I would suggest you share us one file through OneDrive which did not work, and then we could try to reproduce your issue.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 7, 2017 8:26 AM
  • Hi Edward, Thanks, Here is the file attachment where the above mentioned macro is not working

    https://1drv.ms/w/s!Anst2BMicUiaauwfuFHSjGoMEjs

    Data is paste not on same place where textframe was placed

    Wednesday, March 8, 2017 8:10 AM
  • Hi Fahad,

    Some shapes do not support attached text (lines, freeforms, pictures, and OLE objects, for example). If you attempt to return or set properties that control text in a text frame for those objects, an error occurs.

    I suggest you use the HasText property to determine whether the text frame contains text, as shown in the following example.

    Sub fromtxtbox()
        For Each s In ActiveDocument.Shapes
            If s.TextFrame.HasText Then
            Selection.Collapse WdCollapseDirection.wdCollapseEnd
            s.TextFrame.TextRange.Cut
            Selection.PasteAndFormat (wdFormatOriginalFormatting)
            End If
        Next
    End Sub

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 10, 2017 8:41 AM