OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Closing problems with OOo 1.1.1

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Grooveman
General User
General User


Joined: 17 Feb 2004
Posts: 14

PostPosted: Fri Apr 09, 2004 1:43 am    Post subject: Closing problems with OOo 1.1.1 Reply with quote

I made a program in VB which converts the old documents in to new ones. I used it with OOo 1.1.0 and it was working really good. I have installed the new OOo and my program crashes after generating the first document and closing the OOo-document. If i delete the objDocument.close(true) everyrhing works fine. Why can't I close the document anymore? I tried the Dispose but my program also crashed with this command!
Code:

Option Explicit

Sub DocConverter(sourcefol As String, destfol As String)

    Dim forCount As Integer
    Dim Message As String
    Dim count As Integer
    Dim xPos As Double
    Dim yPos As Double
    Dim bottom, top, lft, rght, pagewidth, pageheight, orientation
    Dim TextTables As Object
    Dim Cursor As Object
    Dim Frame As Object
    Dim FrameCursor As Object
    Dim book As String
    Dim border As Object
    Dim DefPage As Object
    Dim oBookmark As Object
    Dim Doc As Word.Document
    Dim font, charh, vertPosRel, horPosRel, docUrl
    Dim errorfiles(40) As String
    Dim errorCount As Integer
    Dim framewidth As Integer
    Dim str As String
    Dim c As Integer
    Dim convcount As Integer
    Dim shapecount As Integer
   
    convcount = 0
    errorCount = 0
    Dim fs As New FileSystemObject
    Dim f, fc
    Dim fl As File

    Set f = fs.GetFolder(sourcefol)
    Set fc = f.Files
   
    Dim Word As New Word.Application
    OOoCom.Initialize

    Dim args(1) As Object
    Set args(0) = MakeProperty("AsTemplate", False)
    Set args(1) = MakeProperty("Hidden", False)
   
   

    For Each fl In fc
               
     If (Right(fl.Name, 3) = "dot") Then
       
        Word.Visible = True

        Word.Documents.Add (fl.path)
        Set Doc = Word.ActiveDocument

        Set objDocument = objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
        On Error GoTo Errorhandler
       
'       Setup the pageproperties
               
        bottom = (Word.PointsToMillimeters(Doc.PageSetup.BottomMargin)) * 100
        lft = (Word.PointsToMillimeters(Doc.PageSetup.LeftMargin)) * 100
        top = (Word.PointsToMillimeters(Doc.PageSetup.TopMargin)) * 100
        rght = (Word.PointsToMillimeters(Doc.PageSetup.RightMargin)) * 100
        pagewidth = (Word.PointsToMillimeters(Doc.PageSetup.pagewidth)) * 100
        pageheight = (Word.PointsToMillimeters(Doc.PageSetup.pageheight)) * 100
        orientation = Doc.PageSetup.orientation
       

        Set DefPage = objDocument.StyleFamilies.getByName("PageStyles").getByName("Default")
        With DefPage
            .LeftMargin = lft
            .RightMargin = rght
            .BottomMargin = bottom
            .TopMargin = top
            .Width = pagewidth
            .Height = pageheight
        End With
       
'       Copy image from Word doc and paste it in Swriter on the right position
       
        If Doc.Shapes.count >= 1 Then
            For shapecount = 1 To Doc.Shapes.count
                Doc.Shapes(shapecount).Select
                Selection.Copy
   
                Dim bla()
                Call dispatcher.executeDispatch(objDocument.getCurrentController().getFrame() _
                , ".uno:Paste", "", 0, bla())
   
                Dim oShape As Object
                Set oShape = objDocument.getDrawPage().getByIndex(shapecount - 1)
               

                With oShape
                    .Width = (Word.PointsToMillimeters(Doc.Shapes(shapecount).Width)) * 100
                    .Height = (Word.PointsToMillimeters(Doc.Shapes(shapecount).Height)) * 100
                    .AnchorType = 2
'                    .HoriOrientPosition = (Word.PointsToMillimeters(Doc.Shapes(shapecount).left) * 100) + lft
                    .VertOrientPosition = (Word.PointsToMillimeters(Doc.Shapes(shapecount).top) * 100) + top
'                    .HoriOrient = 0
                    .VertOrient = 0
'                    .HoriOrientRelation = 0
                    .VertOrientRelation = 0
                End With
            Next shapecount
        End If
       
'       copy all frames with bookmarks to OOo-doc

        count = Doc.Frames.count

        Set border = createStruct("com.sun.star.table.BorderLine")
        border.OuterLineWidth = 0

        For forCount = 1 To count

            yPos = (Word.PointsToMillimeters(Doc.Frames(forCount).VerticalPosition)) * 100
            xPos = (Word.PointsToMillimeters(Doc.Frames(forCount).HorizontalPosition)) * 100
            charh = Doc.Frames(forCount).Range.font.Size
            font = Doc.Frames(forCount).Range.font.Name
            horPosRel = Doc.Frames(forCount).RelativeHorizontalPosition
            vertPosRel = Doc.Frames(forCount).RelativeVerticalPosition
            framewidth = (Word.PointsToMillimeters(Doc.Frames(forCount).Width)) * 100

            If charh < 0 Or charh > 150 Then
            charh = 10
            End If

            If horPosRel = 0 Then
                xPos = xPos + lft
            End If

            If vertPosRel = 0 Then
                yPos = yPos + top
            End If

            framewidth = pagewidth - xPos - 300
           
            Set Cursor = objDocument.Text.createTextCursor()
            Cursor.gotoNextWord (False)

            Set Frame = objDocument.createInstance("com.sun.star.text.TextFrame")

            With Frame
                .Width = framewidth
                .AnchorType = 2
                .TextWrap = 1
                .TopMargin = 0
                .HoriOrientPosition = xPos
                .VertOrientPosition = yPos
                .BottomMargin = 0
                .LeftMargin = 0
                .RightMargin = 0
                .BorderDistance = 0
                .BackTransparent = True
                .HoriOrient = 0
                .VertOrient = 0
                .HoriOrientRelation = 0
                .VertOrientRelation = 0
                .BackColor = -25132928
            End With

            Call Frame.setPropertyValue("LeftBorder", border)
            Call Frame.setPropertyValue("RightBorder", border)
            Call Frame.setPropertyValue("TopBorder", border)
            Call Frame.setPropertyValue("BottomBorder", border)

            Call objDocument.Text.insertTextContent(Cursor, Frame, True)

            If ActiveDocument.Frames(forCount).Range.Bookmarks.count > 0 Then
            book = ActiveDocument.Frames(forCount).Range.Bookmarks.Item(1).Name
            End If

            Set oBookmark = objDocument.createInstance("com.sun.star.text.Bookmark")
            oBookmark.setName book

            Set FrameCursor = Frame.createTextCursor()
            FrameCursor.Charheight = charh
            FrameCursor.CharFontName = font

            Dim s As String
            s = ActiveDocument.Frames(forCount).Range.Text
            If s Like "[a-z,A-Z,1-9]*" = True Then
                Call Frame.Text.Insertstring(FrameCursor, s, False)
            End If

            Call Frame.Text.insertTextContent(FrameCursor, oBookmark, False)


        Next forCount

'       Save the document in 2 different formats and folders: stw and dot

        Dim Url

        Dim fProperties(3) As Object
        Set fProperties(0) = MakeProperty("Overwrite", True)
        Set fProperties(1) = MakeProperty("FilterName", "MS Word 97")

        Url = ConvertPath(destfol & "\dot\" & fl.Name)
        Call objDocument.storeAsURL(Url, fProperties())

        Set fProperties(1) = MakeProperty("FilterName", "writer_StarOffice_XML_Writer_Template")
        Url = ConvertPath(destfol & "\stw\" & Replace(fl.Name, "dot", "stw"))
        Call objDocument.storeAsURL(Url, fProperties())
        convcount = convcount + 1
nextOne:
        ' Her is the problem situated!!!!
        Call objDocument.Close(True)
        Doc.Close (wdDoNotSaveChanges)
       
      End If
    Next
   
    On Error GoTo 0
   
'   End of program:
'     - displays how many docs were converted
'     - which documents weren't possible to convert

    str = "There are " & fc.count & " files in the folder" & Chr(10) & _
          "The program has converted " & convcount & " files " & Chr(10)

    If errorCount > 0 Then
    str = str + Chr(10) & "Some errors occured while converting following documents :" & Chr(10)

    For c = 0 To errorCount
    str = str + errorfiles(c) & Chr(10)
    Next
    End If

    MsgBox str, vbInformation, "Convert complete"

   
    Word.Quit (wdDoNotSaveChanges)
    Call objDesktop.Terminate
    Exit Sub

Errorhandler:
    errorfiles(errorCount) = fl.Name
    errorCount = errorCount + 1
    Resume nextOne
    End
       
End Sub

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group