Unable to get the Open property of the Workbooks class

1,538 views
Skip to first unread message

sysmod

unread,
Apr 13, 2012, 1:39:11 PM4/13/12
to Excel-DNA
Govert
I'm trying to create a simple test harness .
I get the above error at the .Open line. I presume I'm missing
something basic. Could you tell me?

Thanks
Patrick

<DnaLibrary Language="VB" RuntimeVersion="v4.0" >

<Reference Path="LateBindingApi.Core.dll" />
<Reference Path="OfficeApi.dll" />
<Reference Path="ExcelApi.dll" />

<CustomUI>
<customUI xmlns='http://schemas.microsoft.com/office/2006/01/
customui' >
<ribbon>
<tabs>
<tab id="customTab" label="NetOffice"
insertAfterMso="Developer" keytip="B">
<group id="customGroup" label="Test">
<button id="customButton1" tag="RunTest" label="Run
Test" size="large" keytip="Q"
onAction="RunTagMacro"
imageMso="ResultsPaneStartFindAndReplace"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
</CustomUI>
<![CDATA[

'Imports Microsoft.Office.Core ' what is this for?
Imports ExcelDna.Integration
Imports NetOffice.ExcelApi ' Workbooks

' Can make a class that implements
ExcelDna.Integration.CustomUI.ExcelRibbon
' to get full Ribbon access.
Public Class MyRibbon
Inherits CustomUI.ExcelRibbon

Public Sub OnButtonPressed(control as CustomUI.IRibbonControl)
MsgBox("My Button Pressed on control " & control.Id,,"ExcelDna
Ribbon!")
End Sub
End Class

Public Module Module1
public sub RunTest()
dim sFile as string, wb as Workbook
try
sFile = ExcelDnaUtil.Application.GetOpenFilename("All Excel files
(*.xl*), *.xl*", Nothing, "Test", "Select File")
msgbox(sfile,,"sFile")
'if strcomp(sFile,"False",vbTextCompare)=0 then exit sub
wb = workbooks_open(sFile)
if wb is nothing then
msgbox("Nothing opened",vbExclamation,"RunTest")
else
msgbox(wb.name & vbcrlf & "FileFormat=" &
wb.Fileformat,vbExclamation,"wb")
wb.close
end if
catch Ex as Exception
msgbox(Ex.Message,vbExclamation,"RunTest")
end try

end sub

Function Workbooks_Open(ByVal filename As String) As Workbook
try
Return ExcelDnaUtil.Application.Workbooks.Open(filename:=filename,
updateLinks:=False, readOnly:=False, _
format:=Nothing, password:=Nothing,
writeResPassword:=Nothing, _
ignoreReadOnlyRecommended:=Nothing,
origin:=Nothing, addToMru:=False, _
converter:=Nothing,
corruptLoad:=Nothing, delimiter:=Nothing, _
editable:=False, local:=Nothing,
notify:=Nothing)

'Unable to get the Open property of the Workbooks class

catch Ex as Exception
msgbox(Ex.Message & vbnewline & filename,vbExclamation,"Open")
end try
End Function

End Module

]]>
</DnaLibrary>

Govert van Drimmelen

unread,
Apr 13, 2012, 5:47:43 PM4/13/12
to Excel-DNA
Hi Patrick,

I think you just have to experiment with the parameters a bit - with
your named parameters I think the NetOffice class is not resolving the
method override.
Else maybe ask Sabastian about the NetOffice mapping again.

-Govert

Patrick O'Beirne

unread,
Apr 14, 2012, 4:32:19 AM4/14/12
to exce...@googlegroups.com
I thought the .Open call was OK because it compiled correctly in VS 2010
with Intellisense showing me the parameter names.
I'll ask Sebastian

Patrick O'Beirne

unread,
Apr 16, 2012, 10:15:27 AM4/16/12
to exce...@googlegroups.com
On 13/04/2012 22:47, Govert van Drimmelen wrote:
> Hi Patrick,
>
> I think you just have to experiment with the parameters a bit - with
> your named parameters I think the NetOffice class is not resolving the
> method override.
> Else maybe ask Sabastian about the NetOffice mapping again.
>

Thanks, Govert.
I wanted to specify just three of the 15 parameters of Workbooks.Open.

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.open(v=office.11).aspx

However unlike VBA you cannot use named parameters to skip the ones you
don't need. You must specify at least all the parameters up to the last
one you use.
In specifying all 15, after checking one at a time I finally determined
that two of them - 'format' and 'origin' - have to have values other
than Nothing (which would be the default for Object types)

format:=5 ' or any other valid value, not Nothing
origin:=2 ' or Enums.XlPlatform.xlWindows will do here

Sebastian has sent me new libs to test, so I'll be on to that next.

Patrick

Reply all
Reply to author
Forward
0 new messages