Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2021, 04:29 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with Extraction of Text in 1 TextBox only Windows 10 Help with Extraction of Text in 1 TextBox only Office 2019
Competent Performer
Help with Extraction of Text in 1 TextBox only
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default Help with Extraction of Text in 1 TextBox only

Hello Pros,


I'm been searching for a long time, I'm wondering if there is a way to Extraction of Text in 1 TextBox only. Even tried modifying a copy of a Wonderful scripts to Extract all text from all Shapes types with Texts in them, in an active document, that this forum helped, for the ''Selected'' textbox (shape), I keep getting error messages.

Tried doing it manually, recording my steps, but 1- I can't find the way to have a Shape with a various number, and 2- I get error message on Selection.PasteAndFormat (wdFormatOriginalFormatting).

Any insights would be soooooooooooooo appreciative.

Cendrinne
Reply With Quote
  #2  
Old 11-14-2021, 05:11 PM
Guessed's Avatar
Guessed Guessed is offline Help with Extraction of Text in 1 TextBox only Windows 10 Help with Extraction of Text in 1 TextBox only Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You didn't indicate where you wanted the text to go so I'll show you how to put it in front of the anchor for the textbox.
Code:
Sub GetText()
  Dim aShp As Shape, aRng As Range
  If Selection.ShapeRange.Count > 0 Then
    Set aShp = Selection.ShapeRange(1)
    Debug.Print aShp.TextFrame.TextRange.Text
    Set aRng = aShp.Anchor
    aRng.Collapse Direction:=wdCollapseStart
    aRng.FormattedText = aShp.TextFrame.TextRange.FormattedText
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-14-2021, 08:27 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with Extraction of Text in 1 TextBox only Windows 10 Help with Extraction of Text in 1 TextBox only Office 2019
Competent Performer
Help with Extraction of Text in 1 TextBox only
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Red face Andrew, you mignificant mind you....

Quote:
Originally Posted by Guessed View Post
You didn't indicate where you wanted the text to go so I'll show you how to put it in front of the anchor for the textbox.
Code:
Sub GetText()
  Dim aShp As Shape, aRng As Range
  If Selection.ShapeRange.Count > 0 Then
    Set aShp = Selection.ShapeRange(1)
    Debug.Print aShp.TextFrame.TextRange.Text
    Set aRng = aShp.Anchor
    aRng.Collapse Direction:=wdCollapseStart
    aRng.FormattedText = aShp.TextFrame.TextRange.FormattedText
  End If
End Sub
YES, I don't know how you do it, I'm always amaze by you's Pros.
Sorry, I didn't say where to put it.
Where you did, is perfect. Cause at times, I've already fixed lot's of stuff already in a document that had text boxes. So when I encounter another situation in the same document, I didn't want the new textbox to affect all the others that I've fixed.

Would it be complicated to add, that text box that has been extracted, to be deleted?

I could always do it manually, but I was wondering if it's a challenge?

Regardless, thank you soooooooooo much.

Cendrinne
Reply With Quote
  #4  
Old 11-14-2021, 08:47 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help with Extraction of Text in 1 TextBox only Windows 10 Help with Extraction of Text in 1 TextBox only Office 2019
Competent Performer
Help with Extraction of Text in 1 TextBox only
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Smile Oh I found it, how to add to delete the shape.

It's good to know, I have a choice to delete it or not.

I've added this script below, a line after, .End if

HTML Code:
    Selection.ShapeRange(1).Delete
HTML Code:
Sub Gettext()
'Helped by Guessed (Andrew Lockton), from the MS office Word forum on 2021-11-14

  Dim aShp As Shape, aRng As range
  If Selection.ShapeRange.Count > 0 Then
    Set aShp = Selection.ShapeRange(1)
    Debug.Print aShp.TextFrame.TextRange.Text
    Set aRng = aShp.Anchor
    aRng.Collapse Direction:=wdCollapseStart
    aRng.FormattedText = aShp.TextFrame.TextRange.FormattedText
  End If

    Selection.ShapeRange(1).Delete

End Sub
Thank you so much.
I have to open a new thread for something else, I can't figure out. Remove the default marging in a textbox.

Cendrinne
Reply With Quote
  #5  
Old 11-14-2021, 09:55 PM
Guessed's Avatar
Guessed Guessed is offline Help with Extraction of Text in 1 TextBox only Windows 10 Help with Extraction of Text in 1 TextBox only Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The purpose of the If statement is to avoid the macro erroring if you didn't already have a shape selected. Putting your extra line down there will throw an error if that is the case since there won't be a first object when there are no objects.

It would be better to include that line just before the End If line
aShp.Delete
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
extracting data, help please, textbox



Similar Threads
Thread Thread Starter Forum Replies Last Post
Log file extraction xendistar Excel 0 09-01-2016 02:08 PM
wrapping text around a picture within a textbox ketanco Word 3 04-06-2016 11:07 AM
Help with Extraction of Text in 1 TextBox only Data extraction from a cell! JTevez Excel 2 10-14-2015 11:56 PM
Help with Extraction of Text in 1 TextBox only Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM
Help with Extraction of Text in 1 TextBox only Email Extraction dpad Outlook 1 08-17-2010 06:01 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:27 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