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: 399
  • Last Modified:

Goofy word automation

I wrote a word automation using vb.net. This application formats ascii file to word doc with font size as 8 and font name Courier New. It runs perfectly fine here in UK on Server 2000, all versions of word. It also runs on Server 2003 in UK it formats document with correct font size and font name but here is the problem:
 when document is viewed it displays in double line,while paragraph format shows Singleline. I am completly lost.
 
Thnx in advance.
-kushpaw
0
kushpaw
Asked:
kushpaw
  • 6
  • 4
1 Solution
 
computerg33kCommented:
could u post some code?
0
 
computerg33kCommented:
   Private Sub CreateMailMergeDataFile()
        Dim wrdDataDoc As Word.Document

        Dim iCount As Integer
        ' Create a data source at C:\DataDoc.doc containing the field data.
        wrdDoc.MailMerge.CreateDataSource(Name:="C:\DataDoc.doc", _
              HeaderRecord:="1")
        ' Open the file to insert data.
        wrdDataDoc = wrdApp.Documents.Open("C:\DataDoc.doc")
        For iCount = 1 To 0
            wrdDataDoc.Tables.Item(1).Rows.Add()
        Next iCount
        ' Save and close the file.
        wrdDataDoc.Save()
        wrdDataDoc.ActiveWindow.Close()
    End Sub



                                        CreateMailMergeDataFile()

                                        '    ' Create an instance of Word  and make it visible.
                                        wrdApp = CType(CreateObject("Word.Application"), Word.Application)
                                        wrdApp.Visible = True

                                        ' Add a new document.
                                        wrdDoc = wrdApp.Documents.Add()
                                        wrdDoc.Select()

                                        wrdSelection = wrdApp.Selection()
                                        wrdMailMerge = wrdDoc.MailMerge()

                                        wrdSelection.PageSetup.LeftMargin = 65
                                        wrdSelection.PageSetup.RightMargin = 30
                                        wrdSelection.PageSetup.TopMargin = 50
                                        wrdSelection.PageSetup.BottomMargin = 50



this is how i initate word
0
 
kushpawAuthor Commented:

Here is my code:

      Dim doc As Word.DocumentClass
        Dim appclass As Word.ApplicationClass
        'open a new instance of word
        appclass = New Word.ApplicationClass()
        'open up the word document
        appclass.Visible = False
        doc = appclass.Documents.Open(SourceFile)
        doc.ShowGrammaticalErrors = False
        doc.ShowSpellingErrors = False
        appclass.Selection.Delete(Word.WdUnits.wdCharacter, 3)
        appclass.Selection.WholeStory()

      ' misbehaving line of code on Server 2003
        appclass.Selection.Paragraphs.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle
        'appclass.Selection.Paragraphs.LineSpacing = ""

        Dim rng As Word.Range = doc.Range(0, doc.Characters.Count)
        With rng
            .Font.Size = 8
            .Font.Name = "Courier New"
        End With

        With doc.PageSetup
            .LineNumbering.Active = False
            .Orientation = Word.WdOrientation.wdOrientLandscape
            .RightMargin = 72        '1" = 72 points
            .LeftMargin = 72
            .TopMargin = 36
            .BottomMargin = 36
            .PageHeight = 612       'for landscape orientatation,
            .PageWidth = 792        ' height and width is 11 x 8.5
        End With

        doc.SaveAs(DestFile + ".doc", 0)
        doc.Close()
        appclass.Quit()
        doc = Nothing
        appclass = Nothing
        GC.Collect()
0
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.

 
computerg33kCommented:
well..what happens when that line of code is just taken out?
0
 
kushpawAuthor Commented:
Oops! I meant to say "it runs perfectly fine here in US(not UK) on Server 2000, all versions of word" in my original question.

My original code that runs on server 2000 here in US has only following lines of code for page format and font settings,

appclass.Selection.Font.Size = 8
appclass.Selection.Font.Name = "Courier New"
With doc.PageSetup
            .LineNumbering.Active = False
            .Orientation = Word.WdOrientation.wdOrientLandscape
end with

If I take away the code such as
            .RightMargin = 72        '1" = 72 points
            .LeftMargin = 72
            .TopMargin = 36
            .BottomMargin = 36
            .PageHeight = 612       'for landscape orientatation,
            .PageWidth = 792    
or
          appclass.Selection.Paragraphs.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle

then page is formatted weirdly, and every paragraph is double spaced.  I believe because UK has different Page Setting then us therefore I had to set all properties explicitly but WHY WOULD THE PROGRAM IGNORE LINESPACING RULE . This one line is holding up this project.

Thnx

0
 
computerg33kCommented:
if u take out

appclass.Selection.Paragraphs.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle

how does this affect the page?
0
 
computerg33kCommented:
if that doesn't give u the desired results set
appclass.Selection.Paragraphs.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle
to
appclass.Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle
0
 
kushpawAuthor Commented:
Thanks computerg33k but it did not work.
It seems like for every paragraph mark it find in the document, it adds an extra. I have tried clearformattiong but it did not work either.

0
 
computerg33kCommented:
check your vbcr documents (this puts in a paragraph) and check your insertparagraphbefore's and insertparagraphafter's (if one paragraph has a before and the one paragraph before this paragraph has an after--that will insert two enters)
0
 
kushpawAuthor Commented:
Some one at work found out that, Inserting fake paragraph mark is known bug. Search on google.group for "FAKE PARAGRAPH MARK IN WORD"

Here is the code that solved my problem.

With appclass.Selection.Find
            .Text = "^13^p"
            .Replacement.Text = "^p"
            .Forward = True
            .Wrap = Word.WdFindWrap.wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
End With

 
0
 
moduloCommented:
PAQed with points refunded (125)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now