Editing the format of a Word document

mymyrsx

Member
Joined
Mar 15, 2005
Messages
8
Programming Experience
Beginner
Hi
I have a procedure in vb.net that create a word document. Here is my code

VB.NET:
[LEFT]Dim wrd As Word.Application
Dim doc As Word.Document
Dim rng As Word.Range
Try 
  wrd = New Word.Application wrd.Visible = False
Catch ex As Exception 
  MsgBox("An error occured while printing, please try again")
End Try[/LEFT]
 
[LEFT]doc = wrd.Documents.Add()
rng = doc.Range()[/LEFT]
 
[LEFT]...[/LEFT]
 
[LEFT]For Each StringDr In StringDv 
  Select Case StringDr("No") 
     Case 502 '1.2 
        rng.Text = rng.Text + StringDr("Message") 
     Case 503 '1.2.1 
        rng.Text = rng.Text + StringDr("Message")
     Case 504 '1.2.2 
        rng.Text = rng.Text + StringDr("Message") 
  End Select
Next[/LEFT]
 
[LEFT]doc.SaveAs("c:\OperSeq.doc")
wrd.Quit()[/LEFT]


Now What I would like to have is when I enter in the case 503, I would like that it put this "StringDr("Message")" text in bold in my word document.

Does somebody can help me with this?

Thanks in advance
 
Please help

Ok
I downloaded it. I see the help.

The thing is that I don't know how to select the text that I just added. For now, It put all my text in my document word in the format that I want only for one case. I looked at the selection section but I don't really understand.

Can somebody write me the line for the right selection with my code, or maybe I have to change my code a little bit in each case, I don't mind, As long as I make it works.

Thanks in advance
Please help!
 
now it works but I have another problem

Ok,
now the format is working.
But I have another problem.

First, here is my code:
VB.NET:
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] StringDr [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] StringDv
[/SIZE][SIZE=2][COLOR=#0000ff]  Select[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] StringDr([/SIZE][SIZE=2][COLOR=#800000]"No"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]    Case[/COLOR][/SIZE][SIZE=2] 500 [/SIZE][SIZE=2][COLOR=#008000]'1.0
[/COLOR][/SIZE][SIZE=2]      FirstTopicNumber(StringDr([/SIZE][SIZE=2][COLOR=#800000]"Message"[/COLOR][/SIZE][SIZE=2]))
[/SIZE][SIZE=2][COLOR=#0000ff]    Case[/COLOR][/SIZE][SIZE=2] 501 [/SIZE][SIZE=2][COLOR=#008000]'1.1
[/COLOR][/SIZE][SIZE=2]      SimpleNumber(StringDr([/SIZE][SIZE=2][COLOR=#800000]"Message"[/COLOR][/SIZE][SIZE=2]))
[/SIZE][SIZE=2][COLOR=#0000ff]    Case[/COLOR][/SIZE][SIZE=2] 502 [/SIZE][SIZE=2][COLOR=#008000]'1.2
[/COLOR][/SIZE][SIZE=2]      simpleNumber(StringDr([/SIZE][SIZE=2][COLOR=#800000]"Message"[/COLOR][/SIZE][SIZE=2]))[/SIZE]
[SIZE=2]  [SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Select
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2]doc.SaveAs([/SIZE][SIZE=2][COLOR=#800000]"c:\OperSeq.doc"[/COLOR][/SIZE][SIZE=2])
wrd.Quit()
 
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] TopicNumber([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sText [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2])
  rng = doc.Range(Start:=0, End:=0)
[/SIZE][SIZE=2][COLOR=#0000ff]    With[/COLOR][/SIZE][SIZE=2] rng
      .InsertParagraphBefore()
      .InsertParagraphBefore()
      .InsertParagraphBefore()
      .InsertAfter(Text:=sText)
[/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]      With[/COLOR][/SIZE][SIZE=2] .Font
        .Name = [/SIZE][SIZE=2][COLOR=#800000]"Arial"
[/COLOR][/SIZE][SIZE=2]        .Size = 12
        .Bold = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]      End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]    End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] SimpleNumber([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sText [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2])
  rng = doc.Range(Start:=0, End:=0)
[/SIZE][SIZE=2][COLOR=#0000ff]  With[/COLOR][/SIZE][SIZE=2] rng
    .InsertParagraphBefore()
    .InsertParagraphBefore()
    .InsertAfter(Text:=sText)
[/SIZE][SIZE=2][COLOR=#0000ff]    With[/COLOR][/SIZE][SIZE=2] .Font
      .Name = [/SIZE][SIZE=2][COLOR=#800000]"Arial"
[/COLOR][/SIZE][SIZE=2]      .Size = 10
      .Bold = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]    End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][/SIZE][/SIZE]

Ok, now my problem is when I have something like this:
· If outdoor air is not suitable for economizer cooling, compressor #1 starts to operate in "first stage cooling mode".

I would like that it put the second line at the same column position than the first one.

The value in my "StringDr("Message"))" is
"· If outdoor air is not suitable for economizer cooling, compressor #1 starts to operate in "first stage cooling mode". "

Does Somebody know how to solve this problem?
Thanks in advance
 
Back
Top