Results 1 to 6 of 6

Thread: MSword Table

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    48

    MSword Table

    OK, here is the problem. I have an excel form where we fill out information on a per piece basis. The file is supposed named after what piece is done. I have not perfected that part but that is not my question. I am trying to figure out how to update a MS word table to represent what parts have been done (basically which files exist). For example, if item number 1A2 LS2 was done there would be a file named 1a2ls2.xls. In the MS word table I would have a column titled function and a row titled 1a2 ls2. I would need it take information from 2 specific cells from the excel file if it does excess.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MSword Table

    Welcome to the Forums.

    Sounds like you need to list the folder contents of *.xls files into a Word table. But where are you needing the 2 cells of data from
    the Excel file to go?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MSword Table

    This should get you started.
    VB Code:
    1. 'ThisDocument
    2. Option Explicit
    3. 'Add a reference to MS Excel xx.0 Object Library
    4. Private moApp As Excel.Application
    5.  
    6. Private Sub Document_Open()
    7.     Dim oWB As Excel.Workbook
    8.     Dim oTable As Word.Table
    9.    
    10.     'ToDo: Check for Excel files in some directory.
    11.     '
    12.     'If file(s) are found then create an Excel object
    13.     Set moApp = New Excel.Application
    14.     moApp.Visible = False 'Dont know if you want to show the workbook or not.
    15.     'Open the first workbook
    16.     Set oWB = moApp.Workbooks.Open("D:\Test1.xls")
    17.     Set oTable = Documents(1).Tables(1)
    18.     'Add the Excel Cell value to a Word table cell
    19.     oTable.Cell(2, 1).Range.Text = oWB.Sheets(1).Cells(1, 1).Value
    20.     oWB.Close
    21.     Set oWB = Nothing
    22.     moApp.Quit
    23.     Set moApp = Nothing
    24.     Set oTable = Nothing
    25. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    48

    Re: MSword Table

    Hey that looks like it may work with a little tweaking.

    Thanks alot Ill let ya know what the results are

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: MSword Table

    I didnt know exactly what you needed other then accessing Excel from Word and accessing the table cells.

    Sure, just post back so we know if you got it solved or need more help.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: MSword Table

    xlsfile = DIR(myfilename)
    will tell you if the file exists if xlsfile is not = ""

    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width