Results 1 to 20 of 56

Thread: Import Worksheets Into TextBox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    863
    Location
    I can't open the document to save as a template. Anyways, a few things. Your table is created by an external data source which is given the named range "Externaldata_1" which can be referred to when copying. Where is your textbox? On the userform or on the document? Either way, I cannot get anymore than 1 line of the copied range to paste in the textbox even though the whole table/named range has been copied to the clipboard. Sorry but I'm giving up. I'll post the code that works to copy the named range/table and pastes the 1st line/row to both a userform textbox and document textbox. The userform has 1 textbox (textbox1) and 2 command buttons and the document has 1 textbox (textbox1). Good luck. HTH. Dave
    'userform code
    Private Sub CommandButton1_Click()
        Call XLTableToWord("Markers")
    End Sub
    
    
    Private Sub CommandButton2_Click()
        Call XLTableToWord("Person")
    End Sub
    
    
    Public Function XLTableToWord(SheetName As String)
        Dim objExcel As Object
        Dim objWorksheet As Object
        ' Application.ScreenUpdating = False
        Set objExcel = CreateObject("Excel.Application")
        objExcel.Workbooks.Open (ThisDocument.Path & "\Triage.xlsm")
        Set objWorksheet = objExcel.Workbooks("Triage.xlsm").Sheets(SheetName)
        objWorksheet.Range("Externaldata_1").Copy
        objExcel.Workbooks("Triage.xlsm").Close
        Set objWorksheet = Nothing
        objExcel.Quit
        Set objExcel = Nothing
        UserForm1.TextBox1.Paste
        ActiveDocument.TextBox1.Paste
        ' Emptying the Clipboard
        ' this DOES NOT empty the clipboard
        ' Set objWorksheet = Nothing
        ' Set objWorkbook = Nothing
        ' Set objExcel = Nothing
        ' Application.ScreenUpdating = True
    End Function
    Last edited by Aussiebear; 01-11-2025 at 04:37 PM.

Posting Permissions

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