none
"我想用VB6.0把ACCESS的地址数据插入到WORD的文章中打印. RRS feed

  • 问题

  • 我想用VB6.0把ACCESS的地址数据插入到WORD的文章中打印.

    我把ACCESS的地址数据插入到WORD的Text Box 中,
    然后用VB6.0控制Text Box 的打印位置.

    我用下面程序但打印的Text Box 位置没反映.
    帮忙看看

    -----------------------------------------
    Private Sub TestPrint()
    Dim Wordapp As Word.Application
    Dim WordDoc As Word.Document
    Dim WordDoc1 As Word.Document
    Dim WordFile As String
    Dim AddressFile As String 'Access
    Dim ObName As String

    Set Wordapp = CreateObject("Word.Application")
    WordFile = "C:\文章.doc"
    Set WordDoc = Wordapp.Documents.Open(WordFile)
    Set WordDoc1 = Wordapp.Documents(1)

    AddressFile = "Test.mdb"
    WordDoc.MailMerge.OpenDataSource Name:=AddressFile, _
    LinkToSource:=True, Connection:="Test"

    WordDoc.MailMerge.Destination = wdSendToNewDocument
    WordDoc.MailMerge.SuppressBlankLines = False
    WordDoc.MailMerge.Execute pause:=True

    ObName = WordDoc.Shapes(1).Name

    WordDoc.Shapes(ObName).Select
    WordDoc.Shapes(ObName).IncrementTop 100.8
    WordDoc.Shapes(ObName).IncrementLeft 100.8

    WordDoc.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord
    WordDoc.MailMerge.DataSource.LastRecord = wdDefaultLastRecord

    Set WordDoc1 = Wordapp.Documents("A4")
    Wordapp.Quit SaveChanges:=wdDoNotSaveChanges
    Set WordDoc1 = Nothing
    Set WordDoc = Nothing
    Set Wordapp = Nothing
    End SUB 

     

    2007年8月2日 7:02

答案

  • 由于在WordDoc.Shapes(ObName).IncrementTop 100.8
    WordDoc.Shapes(ObName).IncrementLeft 100.8
    使用WordDoc.MailMerge.Destination = wdSendToNewDocument,在进行TextBox的移动前已经生成Form letter1,在进行移动只会对test.doc
    中的Text Box产生影响对Form letter1中的Text Box不产生影响,所以应将Text Box移动的代码放在WordDoc.MailMerge.Destination = wdSendToNewDocument后进行。

     

    2007年8月2日 8:50