+ Reply to Thread
Results 1 to 3 of 3

Copying text box content into a word document

Hybrid View

  1. #1
    Registered User
    Join Date
    08-09-2011
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Copying text box content into a word document

    Hi there,

    Need some help with a formula. If by any chance the answer has been given on any other thread, please post a link.

    My objective is to had content from an excel file into a word document. For doing that i use bookmarks and the following code:

    1. For creating the word file
    Set wdApp = GetObject(, "Word.Application")
            
        If Err.Number <> 0 Then
            Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
         
        Set myDoc = wdApp.Documents.Add(Template:="xxxx.dotm")
        wdApp.Visible = True
    2. For coping content

    Sheets("sheet name").Select
        ActiveSheet.OLEObjects("clts_1").Object.SelStart = 0
        ActiveSheet.OLEObjects("clts_1").Object.SelLength = ActiveSheet.OLEObjects("clts_1").Object.TextLength
        ActiveSheet.OLEObjects("clts_1").Object.Copy
         
        With myDoc.Bookmarks
            .Item("clts_1").Range.Paste
        End With
    For convenience, the word bookmark name and the oleobject are the same. This code works ok, my problem is that i there are dozens of text box in dozens of worksheets so that when i write like this for each one i end up with lots of confusing code apart from the time it takes.

    Do anyone now a code that could literary comand excel to chose all text boxes and copy is content to a bookmark with the exact same name? I was trying the For...next formula but i couldn«t make it work so i erased it.

    Thanks in advance

  2. #2
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Copying text box content into a word document

    Can you post a sample workbook?

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Copying text box content into a word document

    Hello there,

    Try the code provided in the following hyperlink, except you will need to change the CheckBox to Textbox

    http://www.mrexcel.com/forum/showthread.php?t=54489

    Sub LoopThruTXT() 
     Dim i As Integer 
        For i = 1 To 30 
               Controls("clts_" & i).Value = "" 
        Next i
    End Sub
    Last edited by rvasquez; 05-02-2012 at 10:24 AM. Reason: Sorry, should've probably posted the textbox option

+ 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