Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Insert formated text into word from vb6 program

I would like to have a list of formated text that i can insert into a word document dependent on selection within my app

i currently use the following code:

Dim objWD As Word.Application
Set objWD = CreateObject("Word.Application")
objWD.Application.Visible = True
objWD.Documents.Add Template:=QuoteTemp, NewTemplate:=False, DocumentType:=0


On Error GoTo vstrQuoteNumber_Err
vstrQuoteNumber = deData.rscomQuotations.Fields("Quote_Number")
objWD.ActiveDocument.Bookmarks("QuoteNumberMain").Select
objWD.Selection.Text = vstrQuoteNumber
vstrQuoteNumber_Res:

but now i would like to be able to insert certain paragraphs with items bolded  and indented

how would i do that.

i am using vb6

thanks
0
Marcusw
Asked:
Marcusw
  • 3
  • 2
1 Solution
 
oleggoldCommented:
0
 
oleggoldCommented:
Quate from above:
Sub InsertAfterMethod()
  Dim MyText As String
  Dim MyRange As Object
  Set MyRange = ActiveDocument.Range
  MyText = "<Replace this with your text>"
  ' Selection Example:
  Selection.InsertAfter (MyText)
  ' Range Example:
  ' (Inserts text at the current position of the insertion point.)
  MyRange.Collapse
  MyRange.InsertAfter (MyText)
End Sub
                        
InsertBefore method example:

Inserts the specified text at the beginning of a range or selection. After this method is applied, the range or selection expands to include the new text.
Sub InsertBeforeMethod()
   Dim MyText As String
   Dim MyRange As Object
   Set MyRange = ActiveDocument.Range
   MyText = "<Replace this with your text>"
   ' Selection Example:
   Selection.InsertBefore (MyText)
   ' Range Example: Inserts text at the beginning
   ' of the active document.
   MyRange.InsertBefore (MyText)
End Sub
      
0
 
oleggoldCommented:
You could use
   MyText = Yourlist.item(i).Text
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GrahamSkanRetiredCommented:
Sub InsertandFormatSomeText()
    Dim objWD As Word.Application
    Dim wdRange As Word.Range
   
    Set objWD = CreateObject("Word.Application")
    objWD.Application.Visible = True
    objWD.Documents.Add Template:=QuoteTemp, NewTemplate:=False, DocumentType:=0
   
   
    On Error GoTo vstrQuoteNumber_Err
    vstrQuoteNumber = deData.rscomQuotations.Fields("Quote_Number")
    Set wdRange = objWD.ActiveDocument.Bookmarks("QuoteNumberMain").Range
    wdRange.Text = vstrQuoteNumber
    wdRange.Bold = True
    'Optional step to redefine the bookmark, ensuring that it defines the new text.
    objWD.ActiveDocument.Bookmarks.Add "QuoteNumberMain", wdRange
vstrQuoteNumber_Res:
End Sub
0
 
MarcuswAuthor Commented:
sorry i don't think i was clear, the code i am using  insert the text fine, i would just like to be able to format it, ie.
<Bold>Product 1</Bold> this is our best product.<newline>
         <indent><bold>Product 1 Access<bold><newline>

is that any clearer?
0
 
GrahamSkanRetiredCommented:
This will insert the new text as a new paragraph. It applies bold character formatting (as before). It then applies paragraph formatting, indenting by 100 points.

    wdRange.Text = vstrQuoteNumber & vbCr
    wdRange.Bold = True
    wdRange.ParagraphFormat.LeftIndent = 100 '(Points)
   
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now