Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1041|回复: 0

VBA WORD表格光标定位问题

[复制链接]
发表于 2022-5-28 19:10 | 显示全部楼层 |阅读模式


各位大神们 大家好


EXCEL VBA导出数据写入WORD模板文档中的表格中
问题是FOR循环中的下面代码不起作用不知是何原因
WORD表格中光标无法定位到当前表格的行尾及换行(回车符)
光标总是定位到在表格写入的字符前面
比如(光标[size=26.6667px]OB 1080 (PO 64681) 150PCS
望给与指点 谢谢
            .Selection.EndKey Unit:=wdLine
            .Selection.TypeParagraph




Dim wdcx As Object
Dim wd As Object
Set wdcx = CreateObject("word.application")
Set wd = wdcx.documents.Open(path & "\Jewellery AND HAIR delivery form template(QINGDAO).docx")
wdcx.Visible = True
    With wdcx
        .ActiveDocument.Tables(2).Cell(4, 2).Select
        .Selection.Range.text = arr(5, 14)
        .ActiveDocument.Tables(2).Cell(4, 3).Select
        .Selection.Range.text = arr(5, 14)
        .ActiveDocument.Tables(4).Cell(2, 2).Select
        .Selection.Range.text = T & "CTN"
        .ActiveDocument.Tables(4).Cell(2, 3).Select
        .Selection.Range.text = arr(X - 1, 18) & "Kg" & " " & arr(X - 1, 20) & "CBM"
        .ActiveDocument.Tables(5).Cell(2, 2).Select
        For i = 0 To UBound(brr)
            .Selection.Range.text = brr1(i) & " " & brr2(i) & "PCS"
            .Selection.EndKey Unit:=wdLine
            .Selection.TypeParagraph
        Next i
        .ActiveDocument.Tables(5).Cell(3, 2).Select
        .Selection.Range.text = arr(X - 1, 7) & " " & "PCS"
    End With


  
Service  Required ( i.e Express,  Economy)
  
  
  
Remarks
  
  
OB 1080 (PO 64681) 150PCS
  
TOTAL
  
2375 PCS


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-9-21 17:13 , Processed in 0.325848 second(s), 5 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表