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 guess don't knock it until U try it and if it works keep doing it would apply here. Back to your needs, I don't quite follow your overwriting concerns and/or how 1 button may overwrite the other... it seems like you need to add some module level boolean variable to act as a key/switch. Maybe in combination with some kind of textbox change event? I see that the above code for the 2 buttons are actually slightly different and maybe could be changed into 1 function which may be useful....
    Public Function XLTableToWord(SheetName As String)
        Dim objExcel As Excel.Application
        Dim objWorksheet As Excel.Worksheet
        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("A1").CurrentRegion.Copy
        objExcel.Workbooks("Triage.xlsm").Close
        Set objWorksheet = Nothing
        Set objExcel = Nothin
        ' Pasting into the document within TextBox3
        TextBox3(1).Range.Selection.PasteExcelTable _
        LinkedToExcel:=False, WordFormatting:=True, RTF:=False
        ' Emptying the Clipboard
        Set objWorksheet = Nothing
        Set objWorkbook = Nothing
        Set objExcel = Nothing
        Application.ScreenUpdating = True
    End Function
    To operate...

    Call XLTableToWord("Markers")
    Call XLTableToWord("Person")
    If you could post a representative XL file with a table that you're using, I'm guessing that SamT, myself or others could create a Word userform to trial and achieve your desired outcome. HTH. Dave
    Last edited by Aussiebear; 01-11-2025 at 04:35 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
  •