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




Reply With Quote