Option strict question.

B

Bob

I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub

When my project properties has Option strict On (which is what I want) I get
a blue underline in the IDE under the variable Fname (string type) and it
tells me that the string type can not be converted to object implicitly. I
do look at the intellisense of the Open method and I see the parameter
filename is of type object.

What do I need to do to be able to use my passed parameter Fname in the Open
method?

Thanks for any help

Bob
 
A

AMDRIT

I cannot use office interop, however if the input is an object of a string,
could you simply use cObj(somestring)?
 
C

Cor Ligthert [MVP]

Bob,

Did you try it explicitly
dim oFname as object = Fname
doc = MyWord.Documents.Open(oFname)

or just cast it
doc = MyWord.Documents.Open(DirectCast(Fname,object))

Office interop is not my favorite kind of sport therefore just a gues.

Cor
 
C

Chris Dunaway

Bob said:
I got a bit of code that launches Word and opens a file, as follows
Private sub OpenWord(Byval Fname as string)

Dim MyWord As New Microsoft.Office.Interop.Word.Application

Dim doc As Microsoft.Office.Interop.Word.Document

doc = MyWord.Documents.Open(Fname)

doc.activate()

MyWord.visible = true

end sub

Do you need to control the Word session? Why not use the Process
class:

Process.Start(Fname)

That should automatically start Word with that document.
 
J

Jim Wooley

Process.Start seems to be a much simpler solution if it meets the OP's needs.
I would second it. The big trick with the PIA's (primary interop assemblies)
is that they're a PIA. This is particularly true if you deploy to clients
who have differing versions of office installed as the PIA's are targeted
to individual office versions.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 
B

Bob

Yeah I tried that and it works, thanks Cor
Bob
Cor Ligthert said:
Bob,

Did you try it explicitly
dim oFname as object = Fname
doc = MyWord.Documents.Open(oFname)

or just cast it
doc = MyWord.Documents.Open(DirectCast(Fname,object))

Office interop is not my favorite kind of sport therefore just a gues.

Cor
 
B

Bob

Thanks I will try the process ,
I was having a problem with the distributed test app that would not start
Word, so you may have saved me anoter problem. Thanks again
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top