|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Option strict question.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 I cannot use office interop, however if the input is an object of a string,
could you simply use cObj(somestring)? Show quoteHide quote "Bob" <bduf***@sgiims.com> wrote in message news:%233p5m47vGHA.4880@TK2MSFTNGP04.phx.gbl... >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 > > 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 Show quoteHide quote "Bob" <bduf***@sgiims.com> schreef in bericht news:%233p5m47vGHA.4880@TK2MSFTNGP04.phx.gbl... >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 > > Yeah I tried that and it works, thanks Cor
Bob Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:uDxwqJ8vGHA.2260@TK2MSFTNGP03.phx.gbl... > 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 > > "Bob" <bduf***@sgiims.com> schreef in bericht > news:%233p5m47vGHA.4880@TK2MSFTNGP04.phx.gbl... >>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 >> >> > > Bob wrote:
Show quoteHide quote > I got a bit of code that launches Word and opens a file, as follows Do you need to control the Word session? Why not use the Process> 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 class: Process.Start(Fname) That should automatically start Word with that document. 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 Show quoteHide quote > Bob wrote: > >> 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. > 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 Show quoteHide quote "Chris Dunaway" <dunaw***@gmail.com> wrote in message news:1155576037.273409.64370@m79g2000cwm.googlegroups.com... > Bob wrote: >> 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. >
Active Directory
Populating date into SQL How to mask console password input How to query the table in a dataset? VB.NET and Microsoft Word problem: topic becomes read-only IE input box from TreeView Compiling list of items that WinForms can do, WebForms cannot Waiting for com program to terminate Creating Reports from SQL data Filename from Open With |
|||||||||||||||||||||||