开发者

Paste VBA 2-Dim String array into Word Table

I have an abstraction of a table hold als a two dimensional S开发者_Python百科tring array in Word VBA.

Now I want to save this array into a table in a word document, without iteration through both dimensions...afaik there is a method to get a Range(...) content from excel as array...

e.g.:

Dim rng As Excel.Range
Set rng = excelTabelle.Range("A4:F" + CStr(lastRow))
arrData = rng.Value

is there a similar solution for pasting this into a Word table?

Iterating needs too much time for the execution, so I'm looking for a more efficient way to do that.

Greets, poeschlorn


One solution may be to utilize the clipboard for your needs. It is not so easy as in Excel, but perhaps fast enough for you. Here is some sample code how to get some text through the clipboard into a 2x3 word table (add a reference to Microsoft Forms 2.0 object library to your VBA doc):

Dim oData As New DataObject
Dim sText As String

' Navigate to the top-left cell of your table (just an example)
Selection.HomeKey Unit:=wdStory

' Put text to the clipboard
sText = "X1" & vbTab & "B1" & vbTab & "C1" & vbCrLf
sText = sText & "A2" & vbTab & "B2" & vbTab & "C2" & vbCrLf

On Error Resume Next
oData.SetText sText
oData.PutInClipboard
On Error GoTo 0

' Select the needed rows and columns of the table'
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend

' Paste the clipboard to the table '
Selection.Paste

I suggest that you adapt this to put an arbitrary 2-dimensional array into a string and paste it in a similar manner. If you need more help, come back give us more details, please.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜