MartyConnelly
martyconnelly at shaw.ca
Wed Aug 3 18:49:56 CDT 2005
'For early binding with a reference to Word
' Dim objWD As Word.Application
' Dim WordDoc As Word.Document
' Dim WordRange As Word.Range
'For Late binding without a reference to Word use generic Object
Dim objWD As Object
Dim WordDoc As Object
Dim WordRange As Object
' In certain cases using nodes, you may have to use a variant rather than Object
There is a way to handle all this with conditional compile statements
but it is sometimes easier to just add and switch comment out statements
as needed.
Kim Wiggins wrote:
>When I try to remove the reference on my computer and try to run the application it errors out. Shouldn't it run on my system without a reference if I am using late binding like you said? Should I try to set the reference at runtime with a command that references the appropriate object on the system I am using? Does anyone know what the syntax is to set the reference at runtime? Does that mean I need to download msword8.olb and msword9.olb? If so, where do I get those from? Here is my code:
>
>Private Sub cmdLogEntry_Click()
> ' Declare the variable.
> Dim objWD As Word.Application
> Dim WordDoc As Word.Document
> Dim WordRange As Word.Range
> Dim strPath As String
> Dim strFile As String
> Dim strFile1 As String
> Dim strFile2 As String
> Dim strFile3 As String
> Dim strFile4 As String
> Dim strDate As String
> Dim strDate2 As Variant
> Dim strDate1 As String
> Dim strActions As String
> Dim strActions1 As String
> strDate2 = Null
>
> On Error GoTo SubErr
> ' Set the variable (runs new instance of Word.)
> Set objWD = CreateObject("Word.Application")
>
> 'make application visible
> objWD.Application.Visible = True
>
> 'Get Path of Current DB
> strPath = frmSplash.strPath
>
> 'Strip FileName to Get Path to Doc
> Do
> lngInStr = InStr(lngInStr + 1, strPath, "\")
> Loop While (InStr(lngInStr + 1, strPath, "\") <> 0)
>
> 'Get path up to the last \
> strPath = Left(strPath, lngInStr)
>
> 'Append document name onto the end of the stripped path
> strFile = strPath & "AirframeTemplate.doc"
> strFile1 = strPath & "RtEngineTemplate.doc"
> strFile2 = strPath & "LtEngineTemplate.doc"
> strFile3 = strPath & "RtPropTemplate.doc"
> strFile4 = strPath & "LtPropTemplate.doc"
>
> 'open the word document
> Set doc = objWD.Documents.Open(strFile)
>
>
>Kim Wiggins <kimjwiggins at yahoo.com> wrote:
>Thanks so much Marty and Marcel for helping me to understand this better. This is my first attempt at automation. Unfortunately, I will not see this user until Saturday so I can't test it out until then but I will let you know next week if everything went well. Thanks
>
>MartyConnelly wrote:You are using late binding so you don't need any references set to Word,
>which maybe causing the problem
>It might be useful to have a reference if using intellisense or looking
>at object browser
>but you would remove the reference before deploying with late binding.
>With late binding it will grab the highest version of word on the system
>You might be using some esoteric part of word say using xml file
>routines that don't exist
>in Word 97, so you may want to check the version of word running to
>avoid problems
>with lower versions.
>
>On Error Resume Next
>' grab word if already running
>Set objWord = GetObject(, "Word.Application")
>On Error GoTo 0
>' or if word not already running error Err.Number = 429 or
>set to nothing
>If objWord Is Nothing Then
>
>Set objWord = CreateObject("Word.Application")
>Debug.Print objWord.Version
>
>' if Word 97 SP2 then Word Version= 8.0b
>' Word 9 opens a separate window for each document.
>' Prior to Word 9, all documents opened in the same window.
>End If
>
>
>Kim Wiggins wrote:
>
>
>
>>I am using
>>Set objWord = CreateObject("Word.Application")
>>
>>Do you think that could be the problem?
>>Kim
>>
>>
>>MartyConnelly wrote:
>>Are you using early or late binding.
>>Set objWord = CreateObject("Word.Application")
>>or
>>Set objWord = New Word.Application
>>Funny things may happen with early binding if newer versions of word
>>installed and then uninstalled.
>>
>>Kim Wiggins wrote:
>>
>>
>>
>>
>>
>>>Hey everyone
>>>Hope all is well. I am not. I coded an automation report in VB6 using Word and it works fine on my work laptop and my laptop at home. But when I install it on the users computer, it gives me the standard application error and shuts down. It says "My_app_name has encountered an error and must close" and then it offers to send a report. Well that is flooring me because it runs in the development environment on both machines just fine.
>>>Can anyone think of anything that I am missing or overlooking?
>>>Thanks
>>>Kim
>>>
>>>
>>>---------------------------------
>>>Start your day with Yahoo! - make it your home page
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>
--
Marty Connelly
Victoria, B.C.
Canada