Conversion issue with option strict by: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
|
| | Reply: by: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
|
| | Reply: by:John
|
| | Dim WordDoc As Word.Document
|
| | Reply: by:John
|
| | PS: Option Explicit on as well. Thanks.
Regards
|
| | Reply: by:John
|
| | I have tried this;
WordDoc = WordApp.Documents.Add(CObj(Temp)) and the error has gone. Is this correct?
Thanks
Regards
|
| | Reply: by: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
|
0 Comments:
Post a Comment
<< Home