+ Reply to Thread
Results 1 to 3 of 3

Reading Word TextBoxes and Transferring Contents to Excel

  1. #1
    Registered User
    Join Date
    06-26-2006
    Posts
    11

    Reading Word TextBoxes and Transferring Contents to Excel

    So I have all these word documents with the same format. They have all these textboxes that contain "name", "date", "state", "telephone #", etc., respectively.

    I'm trying to create a database using these .doc files. One way is to manually open all the .doc files and manually type into Excel the name, date, state, telephone, etc into each column. But this is tedious!

    I'm sure there's a way for Excel to search all the textboxes from Word and automatically transfer it all into one Excel database.

    I found something on the web that converts Word Comments into Excel. I think it would help in what I'm trying to do:

    --------------------------------------------------------------
    Public Sub PullWordNotes()

    Dim WordApplication As Word.Application
    Dim WordDocument As Word.Document
    Dim DocumentPath As String
    Dim TargetComment As Word.Comment
    Dim DestSheet As Worksheet
    Dim DestRow As Long

    Set WordApplication = New Word.Application
    DocumentPath = Application.GetOpenFilename(FileFilter:="Microsoft Word Files (*.doc),*.doc", Title:="Select template narrative Word document")
    If DocumentPath = "False" Then
    Exit Sub
    End If

    Set WordDocument = WordApplication.Documents.Open(DocumentPath, ReadOnly:=True)

    Set DestSheet = Sheets("Sheet1")
    DestSheet.Cells.ClearContents
    DestSheet.[A1] = "Comment"
    DestSheet.[B1] = "Referenced Text"
    DestRow = DestSheet.[A65536].End(xlUp).Row

    For Each TargetComment In WordDocument.Comments
    DestSheet.[A2:A65536].Cells(DestRow) = TargetComment.Range.Text
    DestSheet.[B2:B65536].Cells(DestRow) = TargetComment.Scope.Text
    Next TargetComment

    WordDocument.Close False
    WordApplication.Quit

    End Sub

    --------------------------------------------------------------

    Now... that just transfers Comments from Word. I'm trying to transfer Text Boxes from Word. I'm knowledgable in VBA, but I cannot frind the TextBox counterpart to Comments. All I found was Controls, ControlCollections, but I don't know how to make it work.

    Anyone got any suggestions? Thanks

  2. #2
    Registered User
    Join Date
    06-26-2006
    Posts
    11
    Oh, I also forgot to ask: what do I reference?

  3. #3
    Registered User
    Join Date
    06-26-2006
    Posts
    11
    Ok I solved the problem for those who want a solution:

    Dim DestString As String
    DestString = WordDocument.Shapes("Text Box 7").TextFrame.TextRange.Text

    Now I have another problem, albeit minor one. The String always ends with a square symbol. It looks like a small, blocky zero and always appears at the end of every string that the .Text method returns. What's up with this? I did the hard part already, so please help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1