在Word 2007中创建表并填充列表框选择 [英] Create Table in Word 2007 and populate with a List box selection

查看:121
本文介绍了在Word 2007中创建表并填充列表框选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好VB代码的人,

当我从Word 2007用户窗体的列表框中选择或多选一个项目然后按一个按钮时,我找不到正确的代码。我希望它从我在列表框中选择的项目在Word 2007中创建一个表。用户表单从Excel填充,它工作正常。下面是用于使用Excel数据填充用户表单的VB代码。任何帮助是极大的赞赏。谢谢



Hello VB Code people,
I'm having trouble finding the correct code that when I select or multi-select an item from a list box in a Word 2007 userform and then press a button. I want it to create a table in Word 2007 from the items that I've selected in the list box. The userform gets populated from Excel and it works fine. Below is the VB Code for populating the userform with Excel data. Any help is greatly appreciated. Thank you

Private Sub Userform_Initialize()
Dim strOffice As String
Dim i As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
  strOffice = "Test"
  'Open the spreadsheet containing the data
  Set db = OpenDatabase("C:Testdata.xlsx", False, False, "Excel 12.0; IMEX=1;")
  'Retrieve the recordset
  Set rs = db.OpenRecordset("SELECT * FROM `Test`")
  'Set the number of Columns = number of Fields in recordset
  ListBox1.ColumnCount = rs.Fields.Count
  'Determine the number of retrieved records
  With rs
    .MoveLast
    i = .RecordCount
    .MoveFirst
  End With
  'Load the listbox with the retrieved records
  ListBox1.Column = rs.GetRows(i)
  'Cleanup
    
  rs.Close
  db.Close
  Set rs = Nothing
  Set db = Nothing
lbl_Exit:
  Exit Sub
    
End Sub

推荐答案

你应该忘了关于DAO。使用 ADO.net [ ^ ]!



如何使用ADO.NET使用Visual Basic在Excel工作簿中检索和修改记录。 NET [ ^ ]

从.NET应用程序访问Microsoft Office数据 [ ^ ]

使用ADO.NET处理Excel文件 [ ^ ]

使用ADO和ADO.NET与EXCEL:资源和已知问题 [ ^ ]



这是链接的集合(教程) )如何使用Word表进行演练:

如何:以编程方式创建Word表 [ ^ ]

演练:在Word中创建表 [ ^ ]

如何:Progr ammatically将行和列添加到Word表 [ ^ ]

自动化Word数据插入和提取表 [ ^ ]

如何:以编程方式使用文档属性填充Word表格 [ ^ ]

如何:将表格插入文字处理文件 [ ^ ]



祝你好运!
You should forget about DAO. Use ADO.net[^]!

How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET[^]
Accessing Microsoft Office Data from .NET Applications[^]
Using ADO.NET to work with Excel files[^]
USING ADO AND ADO.NET WITH EXCEL: Resources and Known Issues[^]

Here is a collection of links (tutorials) how to walkthrough with Word tables:
How to: Programmatically Create Word Tables[^]
Walkthrough: Creating a Table in Word[^]
How to: Programmatically Add Rows and Columns to Word Tables[^]
Automating Word Tables for Data Insertion and Extraction[^]
How to: Programmatically Populate Word Tables with Document Properties[^]
How to: Insert a table into a word processing document [^]

Good luck!


这篇关于在Word 2007中创建表并填充列表框选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆