AllExperts > Visual Basic 
Search      
Visual Basic
Volunteer
Answers to thousands of questions
 Home · More Visual Basic Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Robert Nunemaker
Expertise
String manipulation, Database access and usage, Class creation, and encapsulation are my strong suits. Active X Controls and DLL`s also. Although I don`t deal with Crystal - frankly because I don`t like it; I prefer to do things manually.

Experience
Employment history: Programmed with the Air Force for 15 years, and have continued in the private sector for the past 1 year. Used VB (all versions) for the past 8 years.

Organizations: MCP and MCSD certified.

Education: Computer Science Bachelor degree.

Awards: MCP and MCSD certified.

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > Searching Word for Word 2007 Text Boxes and Printing Contect to a File

Visual Basic - Searching Word for Word 2007 Text Boxes and Printing Contect to a File


Expert: Robert Nunemaker - 1/27/2009

Question
Back on 4/28/07 on this forum Jonathan Roach provided the code below for printing the content of a text box in Word to a file.  The code assumed that the text box was "Text1."  I need to print the content of every text box in a document.  I know I can use "Open "c:\filename.ext" For Append As #1" to add each content to the file, but how do I find every text box. (Assume the text boxes are all in the main body of the document, not in headers, footers, etc.)  Thank you very much!

'Begin Code
Open "c:\filename.ext" For Output As #1
Print #1, Text1.Text
Close #1
'End Code  

Answer
In Word 2007, text boxes are slightly different.  They are "Shapes".

So, use:
Dim Doc As Word.Document
Dim oShape As Word.Shape

Set Doc = ActiveDocument

For Each oShape In Doc.Shapes
   Debug.Print "Name: " & oShape.Name & ", Text: " _
       & Replace(oShape.AlternativeText, "Text Box: ", "")
Next


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.