Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2014, 06:09 AM
marksm33 marksm33 is offline Data from hidden internal tables feeding listboxes in same Word Document Windows 7 64bit Data from hidden internal tables feeding listboxes in same Word Document Office 2013
Novice
Data from hidden internal tables feeding listboxes in same Word Document
 
Join Date: Jan 2014
Posts: 12
marksm33 is on a distinguished road
Cool Data from hidden internal tables feeding listboxes in same Word Document

Hello there,



I'm currently pulling data for my listboxes in an MS Word document from a separate document in Excel. I'd like to pull the data instead from hidden tables within the same Word Document. I can find some answers in the FAQ sections about pulling data from EXTERNAL sources, but not from within.

Any ideas to point me in my next right direction would be appreciated. This is the code that I am currently using for one of my listboxes. I use Office 2010 on a Windows 7 machine.

Thanks in advance, Mark:
Code:
Option Explicit

Private Sub UserForm_Initialize() 
     'Late binding. No reference to Excel Object required.
    Dim xlApp As Object 
    Dim xlWB As Object 
    Dim xlWS As Object 
    Dim cRows As Long 
    Dim i As Long 
    Dim LR As Long 
    Set xlApp = CreateObject("Excel.Application") 
     'Open the spreadsheet to get data
    Set xlWB = xlApp.Workbooks.Open("C:\Users\mark.miller\Desktop\Te1.xltm") 
    Set xlWS = xlWB.Worksheets("Evidence") 
    On Error Goto 0 
    cRows = xlWS.Range("$A1:$A15").Rows.Count 
    Me.lb1aa.ColumnCount = 1 
     'Populate the listbox.
    With Me.lb1aa 
        For i = 2 To cRows 
             'Use .AddItem property to add a new row for each record and populate column 0
            .AddItem xlWS.Range("Ev1a").Cells(i, 1) 
        Next i 
    End With 
     'Clean up
    Set xlWS = Nothing 
    Set xlWB = Nothing 
    xlApp.Quit 
    Set xlApp = Nothing 
lblaa_Exit: 
    Exit Sub 
End Sub 

Private Sub cb1aa_Click() 
    Dim i As Long 
    Dim strDocs As Variant 
    For i = 0 To lb1aa.ListCount - 1 
        If lb1aa.Selected(i) = True Then 
            strDocs = strDocs & lb1aa.List(i) & vbCr 
        End If 
    Next i 
    strDocs = Left$(strDocs, Len(strDocs) - 1) 
    ActiveDocument.Bookmarks("bm1aa").Range _ 
    .InsertBefore strDocs 
    UF1aa.Hide 
End Sub

Last edited by macropod; 02-19-2014 at 03:35 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 02-19-2014, 03:41 PM
macropod's Avatar
macropod macropod is offline Data from hidden internal tables feeding listboxes in same Word Document Windows 7 32bit Data from hidden internal tables feeding listboxes in same Word Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I suppose the first issue you'll need to address is: How do you propose to hide the table and prevent its deletion?

Once you've resolved that little issue, your 'UserForm_Initialize' sub can be implemented as:
Code:
Private Sub UserForm_Initialize()
   Dim Rng As Range
    Me.lb1aa.ColumnCount = 1
     'Populate the listbox.
    With ActiveDocument.Tables(#)
        For i = 2 To .Rows.Count
             'Use .AddItem property to add a new row for each record and populate column 0
             Set Rng = .Cell(i, 1).Range
             Rng.End = Rng.End - 1
            .AddItem Rng.Text
        Next i
    End With
End Sub
where # is the index number of the table you're pulling the data from.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-21-2014, 07:10 PM
marksm33 marksm33 is offline Data from hidden internal tables feeding listboxes in same Word Document Windows 7 64bit Data from hidden internal tables feeding listboxes in same Word Document Office 2013
Novice
Data from hidden internal tables feeding listboxes in same Word Document
 
Join Date: Jan 2014
Posts: 12
marksm33 is on a distinguished road
Default Thanks!

That worked like a charm. Thanks for the code posting tip, as well. I finally figured that out
Reply With Quote
Reply

Tags
internal source, listbox, table

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data transfer from Word tables to Excel shoro Word 4 10-01-2013 05:08 AM
Data from hidden internal tables feeding listboxes in same Word Document Internal links in Word 2010 MKR Word 2 09-27-2013 05:30 PM
Data from hidden internal tables feeding listboxes in same Word Document Hidden tables? dluhop Word Tables 1 09-04-2011 02:41 AM
Data from hidden internal tables feeding listboxes in same Word Document Tables that carry hidden para styles Ulodesk Drawing and Graphics 4 03-10-2011 08:16 AM
*Big One* feeding sql server data into MS Word 2007 forms vafo Mail Merge 0 02-03-2010 04:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft