Conversion issue with option strict

J

John

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
 
G

Gary Hunt

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
 
J

John

Dim WordDoc As Word.Document
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

highlighted
 
J

John

PS: Option Explicit on as well. Thanks.

Regards

Gary Hunt said:
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

highlighted
 
J

John

I have tried this;

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

Thanks

Regards
 
G

Gary Milton

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
 

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

Similar Threads


Top