"NQuinn" <nq****@iciinc. com> wrote in message
news:10******** *****@corp.supe rnews.com...
Thanks for your help. I'm trying this. Is it correct to Dim all my
workbook, worksheet and range variables as "Object"?
Yes - If you want to use late binding. The advantage being that you do not
have to worry about what version of Office is installed. This is very
useful if you distribute your application to people who may upgrade their
version of Office or may use different versions. **It may not be worth it
for you.** It might be simpler just to change your references since early
binding does have some advantages:
Code executes faster - but I have not found the speed improvement to be
worth it.
You can use intellisense - but I write the code using early binding so when
you type "wdApp.", you get a very handy dropdown list of the properties and
methods of the Word.Applicatio n object. I then make the minor amendments to
the code to use late binding, then remove the reference.
Another important note: If you switch to late binding you will not be able
to use the built-in constants. That is, you will have to re-define them
yourself. You cannot simply write:
wdCell.Range.Pa ragraphFormat.A lignment = wdAlignParagrap hRight
because wdAlignParagrap hRight is constant defined by the Word object
library, unless you wrote:
const wdAlignParagrap hRight = 2
Here is an example of some late-binding code which I posted earlier today:
Private Sub PrintWord(strPa th As String)
On Error GoTo Err_Handler
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("W ord.Application ")
Set wdDoc = wdApp.Documents .Open(strPath)
wdDoc.PrintOut False
Exit_Handler:
On Error Resume Next
wdDoc.Close
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
Exit Sub
Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub