Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Automate Word from VB6

Automate Word from VB6

Scheduled Pinned Locked Moved Visual Basic
questiondatabasehelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Carter Langley
    wrote on last edited by
    #1

    'Start Word and open the document template. Set oWord = CreateObject("Word.Application") oWord.Visible = True Set oDoc = oWord.Documents.Add oDoc.PageSetup.Orientation = wdOrientLandscape oDoc.PageSetup.LeftMargin = 10 oDoc.PageSetup.RightMargin = 10 oDoc.PageSetup.TopMargin = 30 'Insert a paragraph at the beginning of the document. Set oPara1 = oDoc.Content.Paragraphs.Add oPara1.Range.Text = "Diamant Drilling Services Run Report" oPara1.Range.Font.Name = "Arial Rounded MT Bold" oPara1.Range.Font.Color = wdColorBlue oPara1.Range.Font.Size = 28 oPara1.Range.Font.Bold = False oPara1.Range.InsertParagraphAfter oPara1.Range.InsertParagraphAfter Set oPara1 = oDoc.Content.Paragraphs.Add oPara1.Range.Text = "QDC" oPara1.Range.Font.Name = "Arial" oPara1.Range.Font.Color = wdColorBlue oPara1.Range.Font.Size = 8 oPara1.Range.Font.Bold = True Ok, there is the code that opens word, opens a new document and starts to insert some things into it. my problem begins with the last block of code. once it has written the word "QDC", how do i then write another word after it on the same line without overwriting the "QDC":confused: I am extracting info from a database and the recordset is going to be used to populate the document. So you will have the following senario:- QDC TYPE NUMBER SPH423 PDC S6L1543 the second line contains the data that is extracted from the database and has to be inserted under the relevent "column headings". there might be only one record or there might be over 200, depends on what the user has searched for. Any ideas on how to do this guys?

    I 1 Reply Last reply
    0
    • C Carter Langley

      'Start Word and open the document template. Set oWord = CreateObject("Word.Application") oWord.Visible = True Set oDoc = oWord.Documents.Add oDoc.PageSetup.Orientation = wdOrientLandscape oDoc.PageSetup.LeftMargin = 10 oDoc.PageSetup.RightMargin = 10 oDoc.PageSetup.TopMargin = 30 'Insert a paragraph at the beginning of the document. Set oPara1 = oDoc.Content.Paragraphs.Add oPara1.Range.Text = "Diamant Drilling Services Run Report" oPara1.Range.Font.Name = "Arial Rounded MT Bold" oPara1.Range.Font.Color = wdColorBlue oPara1.Range.Font.Size = 28 oPara1.Range.Font.Bold = False oPara1.Range.InsertParagraphAfter oPara1.Range.InsertParagraphAfter Set oPara1 = oDoc.Content.Paragraphs.Add oPara1.Range.Text = "QDC" oPara1.Range.Font.Name = "Arial" oPara1.Range.Font.Color = wdColorBlue oPara1.Range.Font.Size = 8 oPara1.Range.Font.Bold = True Ok, there is the code that opens word, opens a new document and starts to insert some things into it. my problem begins with the last block of code. once it has written the word "QDC", how do i then write another word after it on the same line without overwriting the "QDC":confused: I am extracting info from a database and the recordset is going to be used to populate the document. So you will have the following senario:- QDC TYPE NUMBER SPH423 PDC S6L1543 the second line contains the data that is extracted from the database and has to be inserted under the relevent "column headings". there might be only one record or there might be over 200, depends on what the user has searched for. Any ideas on how to do this guys?

      I Offline
      I Offline
      ips_sun
      wrote on last edited by
      #2

      Use the InsertAfter method. It'll move the insertion point to the end of the insert text, ready for your next insertion. You can also use TypeText but can't remember whether that moves the insertion point or not. Some similar to... Set oPara1 = oDoc.Content.Paragraphs.Add oPara1.Selection.InsertAfter "QDC"

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups