Hello,
without showing use your entiere code for loading,
i think i just reference some code from the macro bibel. OOME_4_0.odt
If i had to guess, i would say, you forgot the "private:factory/swriter"
part in the path/url
Listing 261. Open a document into an existing frame.
Sub UseAnExistingFrame
Dim noArgs() 'An empty array for the arguments
Dim vDoc 'The loaded component
Dim sURL As String 'URL of the document to load
Dim nSearch As Long 'Search flags
Dim sFName As String 'Frame Name
Dim vFrame 'Document Frame
Dim s As String 'Display string
REM Search globally for this
nSearch = com.sun.star.frame.FrameSearchFlag.GLOBAL + _
com.sun.star.frame.FrameSearchFlag.CREATE
REM I can even open a real file for this, but I don't know what files
REM you have on your computer so I create a new Writer document instead
sURL = "file:///andrew0/home/andy/doc1.odt"
sURL = "private:factory/swriter"
REM Create a frame with the name MyFrame rather than _default
sFName = "MyFrame"
vFrame = ThisComponent.CurrentController.Frame
vDoc = vFrame.LoadComponentFromUrl(sURL, sFName, nSearch, noArgs())
If IsNull(vDoc) Then
Print "Failed to create a document"
Exit Sub
End If
REM The name of the frame is MyFrame. Note that the name has nothing
REM to do with the title!
sFName = vDoc.CurrentController.Frame.Name
s = "Created document to frame " & sFName & CHR$(10)
MsgBox s
REM This time, do not allow creation; only allow an existing frame
nSearch = com.sun.star.frame.FrameSearchFlag.Global
sURL = "file:///andrew0/home/andy/doc2.odt"
sURL = "private:factory/scalc"
'sFName = "doc1 – OpenOffice.org Writer"
vDoc = vFrame.LoadComponentFromUrl(sURL, sFName, nSearch, noArgs())
If IsNull(vDoc) Then
Print "Failed to create a document"
Exit Sub
End If
s = s & "Created document to frame " & sFName
MsgBox s
End Sub
Hope that helps.
To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!
Have a nice day and let’s (continue to) “Be excellent to each other!”
Ask / Getting Started:
https://wiki.documentfoundation.org/Ask/Getting_Started