Results 1 to 20 of 56

Thread: Import Worksheets Into TextBox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    403
    Location
    Still plugging away at this one. At the moment I'm getting a 'Compile error: Variable not defined' here, when pressing the first button (haven't even bothered with the second button yet) :-

       ' Create reference to object we want to copy    
        Set objWorksheet = ActiveWorkbook.Worksheets("Markers")
    This is the code that I have for both buttons :-

    ' Add Markers Detail
    Private Sub AggrievedBut_Click()    
        ' Using Early Binding    
        Dim WrdApp As Word.Application
        Dim WrdDoc As Word.Document
        Dim WrdTbl As Word.Table    
        Application.ScreenUpdating = False    
        ' Create reference to object we want to copy    
        Set objWorksheet = ActiveWorkbook.Worksheets("Markers")    
        ' Copying the content from 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:=True, RTF:=False    
        ' Emptying the Clipboard    
        CutCopyMode = False    
    End Sub
    
    ' Add Person Detail
    
    Private Sub PersonBut_Click()    
        ' Using Early Binding    
        Dim WrdApp As Word.Application
        Dim WrdDoc As Word.Document
        Dim WrdTbl As Word.Table    
        Application.ScreenUpdating = False    
        ' Create reference to object we want to copy    
        Set objWorksheet = ActiveWorkbook.Worksheets("Person")    
        ' Copying the content from 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:=True, RTF:=False    
        ' Emptying the Clipboard    
        CutCopyMode = False    
    End Sub
    I can forsee that even if I could get one of the buttons to work, then clicking on the other to add another table will overwrite the previous one in my Word document's TextBox3.
    Last edited by Aussiebear; 01-11-2025 at 04:25 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
  •