Advertisement
princeofisles

RB word automation

Sep 25th, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dim wrdApplication As WordApplication
  2.   dim docDocument As WordDocument
  3.   dim rowInvoiceRow As WordRow
  4.   dim tblWordTable As WordTable
  5.   dim intRowCounter As Integer
  6.   dim intColumnCounter As Integer
  7.  
  8.   wrdApplication = new WordApplication
  9.   wrdApplication.Visible = True
  10.  
  11.   docDocument = wrdApplication.Documents.Add()
  12.  
  13.   'Request #1: type hello
  14.  wrdApplication.Selection.TypeText "Hello"
  15.   'put some paragraphs after the text
  16.  wrdApplication.Selection.InsertParagraph
  17.   wrdApplication.Selection.InsertParagraph
  18.   wrdApplication.Selection.InsertParagraph
  19.  
  20.   'move back to the start of the document so there's some indication of movement
  21.  wrdApplication.Selection.GoTo_(Office.wdGoToLine, Office.wdGoToAbsolute, office.wdGoToFirst)
  22.  
  23.   'adding some paragraphs after the picture so there's some movement when moving to the end of the document
  24.  wrdApplication.Selection.InsertParagraph
  25.   wrdApplication.Selection.InsertParagraph
  26.  
  27.   'Request #2: insert a picture
  28.  wrdApplication.Selection.InlineShapes.AddPicture("C:\Program Files\Microsoft Office\MEDIA\CAGCAT10\j0217698.wmf", false, true)
  29.  
  30.   'Request #3: Move to the end of the document
  31.  wrdApplication.Selection.GoTo_(Office.wdGoToLine, Office.wdGoToLast)
  32.  
  33.   'Request #4: Insert a table
  34.  tblWordTable = docDocument.Tables.Add(wrdApplication.Selection.Range, 5, 2)
  35.  
  36.   'Request #5: fill the table
  37.  for intRowCounter = 1 to 5
  38.     for intColumnCounter = 1 to 2
  39.       tblWordTable.Cell(intRowCounter, intColumnCounter).Range.Select_
  40.       wrdApplication.Selection.TypeText "Row: " + str( intRowCounter) + ", Column: " + str(intColumnCounter)
  41.     Next
  42.   Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement