468,505 Members | 1,938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Conversion issue with option strict

Hi

I am getting conversion errors in the below code on the lines highlighted in
red. Would appreciate any tips on how to fix these errors.

Thanks

Regards
dim Company_ID As String

dim Temp As String

dim WordApp As Word.Application

company_id = "xxxx1"

temp = "c:\...\xxx.dot"

WordApp = New Word.Application

WordDoc = WordApp.Documents.Add(Temp) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.

With WordDoc

.Variables.Add("CompanyID", Company_ID) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.

End With


Nov 20 '05 #1
5 2754
What have you defined WordDoc as? and do you have Option Explicit on as
well?

Most of us code with both Option Explicit and Option Strict turned on -
anything else is just guessing :-)

The template you are passing in is defined as a Variant within the
Documents.Add method so that might be causing the problem but I'm guessing
the definition of WordDoc is the issue.

cheers,

g

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:er*************@TK2MSFTNGP10.phx.gbl...
Hi

I am getting conversion errors in the below code on the lines highlighted in red. Would appreciate any tips on how to fix these errors.

Thanks

Regards
dim Company_ID As String

dim Temp As String

dim WordApp As Word.Application

company_id = "xxxx1"

temp = "c:\...\xxx.dot"

WordApp = New Word.Application

WordDoc = WordApp.Documents.Add(Temp) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.

With WordDoc

.Variables.Add("CompanyID", Company_ID) 'ERROR: Option Strict On disallows implicit conversions from 'System.Object' to 'String'.

End With

Nov 20 '05 #2

Dim WordDoc As Word.Document
"Gary Hunt" <be*******@codequest.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
What have you defined WordDoc as? and do you have Option Explicit on as
well?

Most of us code with both Option Explicit and Option Strict turned on -
anything else is just guessing :-)

The template you are passing in is defined as a Variant within the
Documents.Add method so that might be causing the problem but I'm guessing
the definition of WordDoc is the issue.

cheers,

g

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:er*************@TK2MSFTNGP10.phx.gbl...
Hi

I am getting conversion errors in the below code on the lines
highlighted in
red. Would appreciate any tips on how to fix these errors.

Thanks

Regards
dim Company_ID As String

dim Temp As String

dim WordApp As Word.Application

company_id = "xxxx1"

temp = "c:\...\xxx.dot"

WordApp = New Word.Application

WordDoc = WordApp.Documents.Add(Temp) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.

With WordDoc

.Variables.Add("CompanyID", Company_ID) 'ERROR: Option Strict On

disallows
implicit conversions from 'System.Object' to 'String'.

End With


Nov 20 '05 #3
PS: Option Explicit on as well. Thanks.

Regards

"Gary Hunt" <be*******@codequest.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
What have you defined WordDoc as? and do you have Option Explicit on as
well?

Most of us code with both Option Explicit and Option Strict turned on -
anything else is just guessing :-)

The template you are passing in is defined as a Variant within the
Documents.Add method so that might be causing the problem but I'm guessing
the definition of WordDoc is the issue.

cheers,

g

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:er*************@TK2MSFTNGP10.phx.gbl...
Hi

I am getting conversion errors in the below code on the lines
highlighted in
red. Would appreciate any tips on how to fix these errors.

Thanks

Regards
dim Company_ID As String

dim Temp As String

dim WordApp As Word.Application

company_id = "xxxx1"

temp = "c:\...\xxx.dot"

WordApp = New Word.Application

WordDoc = WordApp.Documents.Add(Temp) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.

With WordDoc

.Variables.Add("CompanyID", Company_ID) 'ERROR: Option Strict On

disallows
implicit conversions from 'System.Object' to 'String'.

End With


Nov 20 '05 #4
I have tried this;

WordDoc = WordApp.Documents.Add(CObj(Temp))
and the error has gone. Is this correct?

Thanks

Regards

"Gary Hunt" <be*******@codequest.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
What have you defined WordDoc as? and do you have Option Explicit on as
well?

Most of us code with both Option Explicit and Option Strict turned on -
anything else is just guessing :-)

The template you are passing in is defined as a Variant within the
Documents.Add method so that might be causing the problem but I'm guessing
the definition of WordDoc is the issue.

cheers,

g

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:er*************@TK2MSFTNGP10.phx.gbl...
Hi

I am getting conversion errors in the below code on the lines
highlighted in
red. Would appreciate any tips on how to fix these errors.

Thanks

Regards
dim Company_ID As String

dim Temp As String

dim WordApp As Word.Application

company_id = "xxxx1"

temp = "c:\...\xxx.dot"

WordApp = New Word.Application

WordDoc = WordApp.Documents.Add(Temp) 'ERROR: Option Strict On disallows
implicit conversions from 'System.Object' to 'String'.

With WordDoc

.Variables.Add("CompanyID", Company_ID) 'ERROR: Option Strict On

disallows
implicit conversions from 'System.Object' to 'String'.

End With


Nov 20 '05 #5
Hi John,

You can either do what you have just done or you can declare Temp as an
Object instead of a String (same goes for Company_ID).

Gary

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
I have tried this;

WordDoc = WordApp.Documents.Add(CObj(Temp))
and the error has gone. Is this correct?

Thanks

Regards

"Gary Hunt" <be*******@codequest.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
What have you defined WordDoc as? and do you have Option Explicit on as
well?

Most of us code with both Option Explicit and Option Strict turned on -
anything else is just guessing :-)

The template you are passing in is defined as a Variant within the
Documents.Add method so that might be causing the problem but I'm guessing the definition of WordDoc is the issue.

cheers,

g

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:er*************@TK2MSFTNGP10.phx.gbl...
Hi

I am getting conversion errors in the below code on the lines

highlighted
in
red. Would appreciate any tips on how to fix these errors.

Thanks

Regards
dim Company_ID As String

dim Temp As String

dim WordApp As Word.Application

company_id = "xxxx1"

temp = "c:\...\xxx.dot"

WordApp = New Word.Application

WordDoc = WordApp.Documents.Add(Temp) 'ERROR: Option Strict On disallows implicit conversions from 'System.Object' to 'String'.

With WordDoc

.Variables.Add("CompanyID", Company_ID) 'ERROR: Option Strict On

disallows
implicit conversions from 'System.Object' to 'String'.

End With



Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by ann | last post: by
reply views Thread by JerryH | last post: by
reply views Thread by JerryH | last post: by
4 posts views Thread by Nikhil Patel | last post: by
7 posts views Thread by Brian Henry | last post: by
4 posts views Thread by John | last post: by
1 post views Thread by =?Utf-8?B?QU1lcmNlcg==?= | last post: by
1 post views Thread by =?Utf-8?B?TWlrZSBN?= | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.