Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.word.vba.general,microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default How to write late-binding code in XL VBA for Word objects?

I'm trying to port working Word VBA code into an Excel VBA module.
Because I don't know which version of Word my users have, I'm writing
it as late-binding code (everything Word is Dim'd as Object). I think
'most everything is going okay so far (we'll find out when I smoke
test!), but I'm wondering about certain Word objects that use methods
and properties not found in Excel.

My question is: when the Word Application object is set and the other
Word objects (docs and ranges) are set, will they be able to access
all the properties and methods of the Word object as if they were
early-bound?

For instance:
rngDoc.Find.Execute _
FindText:="MyText"
Excel Find does not have the Execute method nor the FindText property.

and

rngDoc.MoveEnd Unit:=wdParagraph
likewise has no Excel equivalent.

Should this compile and run okay? Or am I going to have to find new
ways to write this that are compatible with a late-binding routine?

Ed

  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 5,939
Default How to write late-binding code in XL VBA for Word objects?

The properties and methods should be just fine. Once bound to the object at
run time all of the properties and methods of the object will be exposed.
Where you can have an issue is with constants like wdBorderLeft which will
not exist. You will need to replace those constants with their numeric
equivalent (-2 in this case) or you can declare the constants publicly in a
module

Public Const wdBorderLeft as Long = -2

(I kinda like that option as it makes things a bit more readable but to each
his own)
--
HTH...

Jim Thomlinson


"Ed from AZ" wrote:

I'm trying to port working Word VBA code into an Excel VBA module.
Because I don't know which version of Word my users have, I'm writing
it as late-binding code (everything Word is Dim'd as Object). I think
'most everything is going okay so far (we'll find out when I smoke
test!), but I'm wondering about certain Word objects that use methods
and properties not found in Excel.

My question is: when the Word Application object is set and the other
Word objects (docs and ranges) are set, will they be able to access
all the properties and methods of the Word object as if they were
early-bound?

For instance:
rngDoc.Find.Execute _
FindText:="MyText"
Excel Find does not have the Execute method nor the FindText property.

and

rngDoc.MoveEnd Unit:=wdParagraph
likewise has no Excel equivalent.

Should this compile and run okay? Or am I going to have to find new
ways to write this that are compatible with a late-binding routine?

Ed


  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 120
Default How to write late-binding code in XL VBA for Word objects?

Thanks, Jim. I appreciate the boost.

The next question, then, is how to find the constants? Is there an on-
line reference, perhaps? Or do I just have to hunt-and-peck each one
in Word VBA?

Ed

On Aug 28, 2:32 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
The properties and methods should be just fine. Once bound to the object at
run time all of the properties and methods of the object will be exposed.
Where you can have an issue is with constants like wdBorderLeft which will
not exist. You will need to replace those constants with their numeric
equivalent (-2 in this case) or you can declare the constants publicly in a
module

Public Const wdBorderLeft as Long = -2

(I kinda like that option as it makes things a bit more readable but to each
his own)
--
HTH...

Jim Thomlinson



"Ed from AZ" wrote:
I'm trying to port working Word VBA code into an Excel VBA module.
Because I don't know which version of Word my users have, I'm writing
it as late-binding code (everything Word is Dim'd as Object). I think
'most everything is going okay so far (we'll find out when I smoke
test!), but I'm wondering about certain Word objects that use methods
and properties not found in Excel.


My question is: when the Word Application object is set and the other
Word objects (docs and ranges) are set, will they be able to access
all the properties and methods of the Word object as if they were
early-bound?


For instance:
rngDoc.Find.Execute _
FindText:="MyText"
Excel Find does not have the Execute method nor the FindText property.


and


rngDoc.MoveEnd Unit:=wdParagraph
likewise has no Excel equivalent.


Should this compile and run okay? Or am I going to have to find new
ways to write this that are compatible with a late-binding routine?


Ed- Hide quoted text -


- Show quoted text -



  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 5,939
Default How to write late-binding code in XL VBA for Word objects?

Make sure that you have Option Explicit declared at the top of each code
module so that VBA won't declare those as varaibles for you on the fly. Now
your code will not compile if any of those constants exist. Once you have
found them go into Word VBA and hit F2 to bring up a listing of all of the
objects and constants and such. When you find the constants you are looking
for select them and you will be given the value associated with that constant.
--
HTH...

Jim Thomlinson


"Ed from AZ" wrote:

Thanks, Jim. I appreciate the boost.

The next question, then, is how to find the constants? Is there an on-
line reference, perhaps? Or do I just have to hunt-and-peck each one
in Word VBA?

Ed

On Aug 28, 2:32 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
The properties and methods should be just fine. Once bound to the object at
run time all of the properties and methods of the object will be exposed.
Where you can have an issue is with constants like wdBorderLeft which will
not exist. You will need to replace those constants with their numeric
equivalent (-2 in this case) or you can declare the constants publicly in a
module

Public Const wdBorderLeft as Long = -2

(I kinda like that option as it makes things a bit more readable but to each
his own)
--
HTH...

Jim Thomlinson



"Ed from AZ" wrote:
I'm trying to port working Word VBA code into an Excel VBA module.
Because I don't know which version of Word my users have, I'm writing
it as late-binding code (everything Word is Dim'd as Object). I think
'most everything is going okay so far (we'll find out when I smoke
test!), but I'm wondering about certain Word objects that use methods
and properties not found in Excel.


My question is: when the Word Application object is set and the other
Word objects (docs and ranges) are set, will they be able to access
all the properties and methods of the Word object as if they were
early-bound?


For instance:
rngDoc.Find.Execute _
FindText:="MyText"
Excel Find does not have the Execute method nor the FindText property.


and


rngDoc.MoveEnd Unit:=wdParagraph
likewise has no Excel equivalent.


Should this compile and run okay? Or am I going to have to find new
ways to write this that are compatible with a late-binding routine?


Ed- Hide quoted text -


- Show quoted text -




  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.word.vba.general
external usenet poster
 
Posts: 120
Default How to write late-binding code in XL VBA for Word objects?

Jim, this all worked great!! Thank you so much!

Ed


On Aug 28, 3:06 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Make sure that you have Option Explicit declared at the top of each code
module so that VBA won't declare those as varaibles for you on the fly. Now
your code will not compile if any of those constants exist. Once you have
found them go into Word VBA and hit F2 to bring up a listing of all of the
objects and constants and such. When you find the constants you are looking
for select them and you will be given the value associated with that constant.
--
HTH...

Jim Thomlinson



"Ed from AZ" wrote:
Thanks, Jim. I appreciate the boost.


The next question, then, is how to find the constants? Is there an on-
line reference, perhaps? Or do I just have to hunt-and-peck each one
in Word VBA?


Ed


On Aug 28, 2:32 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
The properties and methods should be just fine. Once bound to the object at
run time all of the properties and methods of the object will be exposed.
Where you can have an issue is with constants like wdBorderLeft which will
not exist. You will need to replace those constants with their numeric
equivalent (-2 in this case) or you can declare the constants publicly in a
module


Public Const wdBorderLeft as Long = -2


(I kinda like that option as it makes things a bit more readable but to each
his own)
--
HTH...


Jim Thomlinson


"Ed from AZ" wrote:
I'm trying to port working Word VBA code into an Excel VBA module.
Because I don't know which version of Word my users have, I'm writing
it as late-binding code (everything Word is Dim'd as Object). I think
'most everything is going okay so far (we'll find out when I smoke
test!), but I'm wondering about certain Word objects that use methods
and properties not found in Excel.


My question is: when the Word Application object is set and the other
Word objects (docs and ranges) are set, will they be able to access
all the properties and methods of the Word object as if they were
early-bound?


For instance:
rngDoc.Find.Execute _
FindText:="MyText"
Excel Find does not have the Execute method nor the FindText property.


and


rngDoc.MoveEnd Unit:=wdParagraph
likewise has no Excel equivalent.


Should this compile and run okay? Or am I going to have to find new
ways to write this that are compatible with a late-binding routine?


Ed- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help converting code to late binding XP Excel Programming 2 February 16th 06 05:51 PM
Late Binding to Word Variables ben Excel Programming 2 June 28th 05 03:02 PM
late binding onto Word problem jason Excel Programming 0 June 24th 04 11:44 AM
Early vs Late Binding - Word John Wilson Excel Programming 6 November 13th 03 03:21 PM
DAO objects with late binding in Excel? Chris Excel Programming 0 August 21st 03 07:28 PM


All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"