Results 41 to 56 of 56

Thread: Import Worksheets Into TextBox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location

    Import Worksheets Into TextBox

    Wasn’t sure whether to put this under Word or Excel, but went with Word as this is where the data needs to end up.

    I have two buttons on my Word userform which I need to import a specifically named worksheet table into a specific TextBox. It will not always be necessary to use both buttons, but if they are both used, then the contents of the TextBox should not be overwritten by the other button’s action.

    The Excel Workbook will already be open and the worksheets are already named. The tables do not have a fixed number / range of cells. I can move the Dims to the start of the document if this is needed (save on repetition?) after OptionExplicit.

    Here is what I have so far, which rather helpfully does nothing when either button is pressed.

    ' Add Markers Detail
    
    Private Sub MarkersBut_Click()    
        'Using Early Binding    
        Dim wordApp As Word.Application
        Dim mydoc As Word.Document
        Dim wb As Workbook
        Application.ScreenUpdating = False
        Set wb = ActiveSheet("Markers")    
        ' Copying the content from active Excel worksheet named Markers    
        ThisWorkbook.Worksheets("Markers").Range("A1").Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlDown)).Select.Copy    
        'Pasting into the document within TextBox3    
        TextBox3(1).Range.Selection.PasteExcelTable _
        LinkedToExcel:=False, WordFormatting:=False, RTF:=False    
        'Emptying the Clipboard after use    
        CutCopyMode = False    
    End Sub
    
    ' Add Person Detail
    
    Private Sub PersonBut_Click()    
        ' Using Early Binding    
        Dim wordApp As Word.Application
        Dim mydoc As Word.Document
        Dim wb As Workbook
        Application.ScreenUpdating = False
        Set wb = ActiveSheet("Person")    
        ' Copying the content from active Excel worksheet named Person    
        ThisWorkbook.Worksheets("Person").Range("A1").Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlDown)).Select.Copy    
        ' Pasting into the document within TextBox3    
        TextBox3(1).Range.Selection.PasteExcelTable _
        LinkedToExcel:=False, WordFormatting:=False, RTF:=False    
        ' Emptying the Clipboard after use    
        CutCopyMode = False    
    End Sub
    Last edited by Aussiebear; 01-11-2025 at 04:23 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
  •