MartyConnelly
martyconnelly at shaw.ca
Wed Aug 3 21:46:16 CDT 2005
Not to worry you will eventualy "grok this" and/or "the penny will drop". If you want to early bind, you should use the oldest MsWord olb file available to your clients and to you. as Access will upgrade the reference to the latest version available, Now this is the way it is supposed to work But if you have installed Office 2003 trial version of Word on a system that has also got Office 97 The trial expires and you remove Office 2003 Word and install Access 2003 then try and early bind to Word 97 it will complain about unregistered MSWORD8.OLB At this point you give up and use late binding also giving up some speed. I just realized something, that I hadn't understood before. In VBA the way you specify how the object is bound is by your object declaration. If you declare an object variable as "Object" you are, in fact, telling Visual Basic to use IDispatch, and are therefore late binding: So either Call method works with early binding when you set a declared object variable such as Word Dim objWD As Word.Application Set objWD = CreateObject("Word.Application") or Set objWD = New Word.Application Also Here is how to do a conditional compile to select early and late binding by just switching a constant. Option Explicit #Const LateBindWord = False 'look up condition compile in help #IF...THEN ... #Else Directive 'INFO: Using Early Binding and Late Binding in Automation 'http://support.microsoft.com/default.aspx/kb/245115 'http://support.microsoft.com/default.aspx?kbid=242375 'PRB: Office 97 Automation Client Fails After Re-compilation with Office 2000 'or Later Type Library 'http://support.microsoft.com/default.aspx?kbid=242375 'INFO: Use DISPID Binding to Automate Office Applications Whenever Possible 'http://support.microsoft.com/kb/247579 'INFO: Writing Automation Clients for Multiple Office Versions 'http://support.microsoft.com/kb/244167 Public Sub cmdLogEntry_Click() ' Declare the variable. #If LateBindWord Then 'For Late binding without a reference to Word olb use generic Object Dim objWD As Object Dim WordDoc As Object Dim WordRange As Object #Else 'For early binding with a reference to Word Dim objWD As Word.Application Dim WordDoc As Word.Document Dim WordRange As Word.Range #End If 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.) #If LateBindWord Then Set objWD = CreateObject("Word.Application") #Else 'Again, in Visual Basic the way you specify how the object is bound is by your object declaration. ' If you declare an object variable as "Object" ' you are, in fact, telling Visual Basic to use IDispatch, and are therefore late binding: ' So either Call method works and this doesn't matter Set objWD = CreateObject("Word.Application") 'Set objWD = New Word.Application #End If 'make application visible objWD.Application.Visible = True 'Get Path of Current DB strFile = "C:\Access files\SharePoint\Using Microsoft Windows SharePoint Services with the Microsoft Office System.doc" 'open the word document Set WordDoc = objWD.Documents.Open(strFile) 'blah blah blah End Sub 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