![]() |
Early vs Late Binding - Word
I'm finally getting a taste (quite sour) of Office 2003.
It came with the two new PC's so I didn't have much of a choice. In many (actually all) of the workbooks where I interact with Word, I used Early Binding. Since the initial workbooks were created in Office 2000, when someone with a later version saves the workbook the Word Object reference is set to version 11. I've already read through many of the threads by Chip, Rob, etc. and it's beginning to sink in (but a lot slower than I would have hoped). Whilst still getting a handle on this, I would appreciate it if someone could convert the following code to utilize Late Binding. I can get some of it to work, but not all. Any help would be appreciated. Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRange As Word.Range Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Thanks, John |
Early vs Late Binding - Word
John,
Just change all the declarations for Word objects from "As Word.whatever" to "As Object". -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "John Wilson" wrote in message ... I'm finally getting a taste (quite sour) of Office 2003. It came with the two new PC's so I didn't have much of a choice. In many (actually all) of the workbooks where I interact with Word, I used Early Binding. Since the initial workbooks were created in Office 2000, when someone with a later version saves the workbook the Word Object reference is set to version 11. I've already read through many of the threads by Chip, Rob, etc. and it's beginning to sink in (but a lot slower than I would have hoped). Whilst still getting a handle on this, I would appreciate it if someone could convert the following code to utilize Late Binding. I can get some of it to work, but not all. Any help would be appreciated. Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRange As Word.Range Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Thanks, John |
Early vs Late Binding - Word
Read this John
http://www.erlandsendata.no/english/...baoleolebasics -- Regards Ron de Bruin (Win XP Pro SP-1 XL2002 SP-2) www.rondebruin.nl "John Wilson" wrote in message ... I'm finally getting a taste (quite sour) of Office 2003. It came with the two new PC's so I didn't have much of a choice. In many (actually all) of the workbooks where I interact with Word, I used Early Binding. Since the initial workbooks were created in Office 2000, when someone with a later version saves the workbook the Word Object reference is set to version 11. I've already read through many of the threads by Chip, Rob, etc. and it's beginning to sink in (but a lot slower than I would have hoped). Whilst still getting a handle on this, I would appreciate it if someone could convert the following code to utilize Late Binding. I can get some of it to work, but not all. Any help would be appreciated. Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRange As Word.Range Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Thanks, John |
Early vs Late Binding - Word
Chip,
Thanks for that. I guess I was trying to overcomplicate things. Anyway, your suggestion worked perfectly and many thanks. I have one more associated dilemma, though. Using your suggestion, the correct word document does open. This line of code crashes though (it worked with early binding) Set wordRange = wordDoc.Goto(What:=wdGoToBookmark, Name:="FaxTo") The error that I get is that "This bookmark does not exist", but it does indeed exist. For reference, the coding per your suggestion that did work is as follows: Dim wordApp As Object Dim wordDoc As Object Dim wordRange As Object Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Again...many thanks, John Chip Pearson wrote: John, Just change all the declarations for Word objects from "As Word.whatever" to "As Object". -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "John Wilson" wrote in message ... I'm finally getting a taste (quite sour) of Office 2003. It came with the two new PC's so I didn't have much of a choice. In many (actually all) of the workbooks where I interact with Word, I used Early Binding. Since the initial workbooks were created in Office 2000, when someone with a later version saves the workbook the Word Object reference is set to version 11. I've already read through many of the threads by Chip, Rob, etc. and it's beginning to sink in (but a lot slower than I would have hoped). Whilst still getting a handle on this, I would appreciate it if someone could convert the following code to utilize Late Binding. I can get some of it to work, but not all. Any help would be appreciated. Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRange As Word.Range Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Thanks, John |
Early vs Late Binding - Word
Ron,
Thanks for that. I did read it. There are actually some very detailed threads in Google on the subject and I've perused many of them too. I don't usually ask "homework" type questions, but I was in a bind (an early bind), since I have multiple users sharing files with different versions of Office and I've been running around setting and resetting object references all day. I have everything running okay now on the old version PC's and the new ones are off limits (under pain of death) until I can get this resolved. Thanks, John Ron de Bruin wrote: Read this John http://www.erlandsendata.no/english/...baoleolebasics -- Regards Ron de Bruin (Win XP Pro SP-1 XL2002 SP-2) www.rondebruin.nl "John Wilson" wrote in message ... I'm finally getting a taste (quite sour) of Office 2003. It came with the two new PC's so I didn't have much of a choice. In many (actually all) of the workbooks where I interact with Word, I used Early Binding. Since the initial workbooks were created in Office 2000, when someone with a later version saves the workbook the Word Object reference is set to version 11. I've already read through many of the threads by Chip, Rob, etc. and it's beginning to sink in (but a lot slower than I would have hoped). Whilst still getting a handle on this, I would appreciate it if someone could convert the following code to utilize Late Binding. I can get some of it to work, but not all. Any help would be appreciated. Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRange As Word.Range Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Thanks, John |
Early vs Late Binding - Word
Hi John,
Since you're using Late Binding now, you must be sure to replace all named constants with their actual values. VBA has no idea what wdGoToBookmark is, so you should use -1 instead. You can get the value by going into Word, opening the VBE, and typing ?wdGoToBookmark in the immediate window. BTW, you should use Option Explicit at the top of each module - that way, you would be warned that wdGoToBookmark is undefined. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] John Wilson wrote: Chip, Thanks for that. I guess I was trying to overcomplicate things. Anyway, your suggestion worked perfectly and many thanks. I have one more associated dilemma, though. Using your suggestion, the correct word document does open. This line of code crashes though (it worked with early binding) Set wordRange = wordDoc.Goto(What:=wdGoToBookmark, Name:="FaxTo") The error that I get is that "This bookmark does not exist", but it does indeed exist. For reference, the coding per your suggestion that did work is as follows: Dim wordApp As Object Dim wordDoc As Object Dim wordRange As Object Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Again...many thanks, John Chip Pearson wrote: John, Just change all the declarations for Word objects from "As Word.whatever" to "As Object". -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "John Wilson" wrote in message ... I'm finally getting a taste (quite sour) of Office 2003. It came with the two new PC's so I didn't have much of a choice. In many (actually all) of the workbooks where I interact with Word, I used Early Binding. Since the initial workbooks were created in Office 2000, when someone with a later version saves the workbook the Word Object reference is set to version 11. I've already read through many of the threads by Chip, Rob, etc. and it's beginning to sink in (but a lot slower than I would have hoped). Whilst still getting a handle on this, I would appreciate it if someone could convert the following code to utilize Late Binding. I can get some of it to work, but not all. Any help would be appreciated. Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRange As Word.Range Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Thanks, John |
Early vs Late Binding - Word
Jake,
That did the trick!!! Thanks for the help. you should use Option Explicit at the top of each module As a rule, I usually do. I had it commented out whilst working on this problem. Thanks again, John Jake Marx wrote: Hi John, Since you're using Late Binding now, you must be sure to replace all named constants with their actual values. VBA has no idea what wdGoToBookmark is, so you should use -1 instead. You can get the value by going into Word, opening the VBE, and typing ?wdGoToBookmark in the immediate window. BTW, you should use Option Explicit at the top of each module - that way, you would be warned that wdGoToBookmark is undefined. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] John Wilson wrote: Chip, Thanks for that. I guess I was trying to overcomplicate things. Anyway, your suggestion worked perfectly and many thanks. I have one more associated dilemma, though. Using your suggestion, the correct word document does open. This line of code crashes though (it worked with early binding) Set wordRange = wordDoc.Goto(What:=wdGoToBookmark, Name:="FaxTo") The error that I get is that "This bookmark does not exist", but it does indeed exist. For reference, the coding per your suggestion that did work is as follows: Dim wordApp As Object Dim wordDoc As Object Dim wordRange As Object Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Again...many thanks, John Chip Pearson wrote: John, Just change all the declarations for Word objects from "As Word.whatever" to "As Object". -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "John Wilson" wrote in message ... I'm finally getting a taste (quite sour) of Office 2003. It came with the two new PC's so I didn't have much of a choice. In many (actually all) of the workbooks where I interact with Word, I used Early Binding. Since the initial workbooks were created in Office 2000, when someone with a later version saves the workbook the Word Object reference is set to version 11. I've already read through many of the threads by Chip, Rob, etc. and it's beginning to sink in (but a lot slower than I would have hoped). Whilst still getting a handle on this, I would appreciate it if someone could convert the following code to utilize Late Binding. I can get some of it to work, but not all. Any help would be appreciated. Dim wordApp As Word.Application Dim wordDoc As Word.Document Dim wordRange As Word.Range Dim FileNameAndPath As String FileNameAndPath = ActiveWorkbook.path & "\Forms\Fax_Cover_Master.doc" Set wordApp = CreateObject("Word.Application") Set wordDoc = wordApp.Documents.Open(FileNameAndPath, ReadOnly:=True) Thanks, John |
All times are GMT +1. The time now is 11:15 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com