Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 05-02-2012, 04:11 PM
macropod's Avatar
macropod macropod is offline creating a report table Windows 7 64bit creating a report table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi kannan,

OK, so, if you know where you want the data to go, it's a simple matter of putting it there. Ideally, you'd collate all the data for a given location before inserting it there, though could could work through the data iteratively and output each portion to the appropriate place in the document as you go. Do note that if the same data needs to be replicated in multiple places, it only needs to be output to the document once - you then use cross-referencing for the replication.

Now, suppose you have a table somewhere that you want to add rows to and you know it's the third table. If you're working through the data iteratively, you can use code like:
Code:
Sub Demo()
Dim i As Long, StrData As String
StrData = "Column1,Column2,Column3,Column4,Column5,Column6,..."
With ActiveDocument.Tables(1).Rows
  .Add
  For i = 1 To .Last.Cells.Count
    .Last.Cells(i).Range.Text = Split(StrData, ",")(i - 1)
  Next
End With
End Sub
In this case 'StrData' is the name of whatever variable you're holding the data in. For demonstration purposes, a comma-delimiter is assumed.

Likewise, if you have a bookmarked destination (in this case, named 'MyBookmark') that you want to populate, with a single data stream that you want to turn into a table, you might use code like:
Code:
Sub Demo()
Dim StrHdr As String, StrData As String
StrHdr = "Column1,Column2,Column3,Column4,Column5,Column6"
StrData = "$A$1,$B$1,$C$1,$D$1,$E$1,$F$1" & vbCr & _
          "$A$2,$B$2,$C$2,$D$2,$E$2,$F$2" & vbCr & _
          "$A$3,$B$3,$C$3,$D$3,$E$3,$F$3" & vbCr & _
          "$A$4,$B$4,$C$4,$D$4,$E$4,$F$4" & vbCr & _
          "$A$5,$B$5,$C$5,$D$5,$E$5,$F$5" & vbCr & _
          "$A$6,$B$6,$C$6,$D$6,$E$6,$F$6" & vbCr & _
          "$A$7,$B$7,$C$7,$D$7,$E$7,$F$7" & vbCr & _
          "$A$8,$B$8,$C$8,$D$8,$E$8,$F$8" & vbCr & _
          "$A$9,$B$9,$C$9,$D$9,$E$9,$F$9" & vbCr & _
          "$A$10,$B$10,$C$10,$D$10,$E$10,$F$10"
StrData = StrHdr & vbCr & StrData
Call UpdateBookmark("MyBookmark", StrData)
With ActiveDocument.Bookmarks("MyBookmark").Range
  .ConvertToTable Separator:=","
  .Tables(1).Style = wdStyleTableMediumList2
End With
End Sub
 
Sub UpdateBookmark(BmkNm As String, NewTxt As String)
Dim BmkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = NewTxt
    .Bookmarks.Add BmkNm, BmkRng
  End If
End With
Set BmkRng = Nothing
End Sub
As I said, none of this is especially complicated.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
mail merge, reporting, vb script



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a report table How to keep hyperlinks when creating a table of contents Abacaxi Word 3 04-18-2012 12:24 AM
Creating checkbox linked to table value. sleepinglate Word 0 10-16-2011 11:29 AM
Creating Daily report forms DaveServo Excel 4 05-20-2011 03:38 AM
Creating a footer row in a table? barnkat Word Tables 0 08-13-2010 10:40 AM
Creating table template on Microsoft Word (2003) Tems4pauly Word Tables 3 06-19-2009 06:05 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft