By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 2,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

VBA in Word

P: 9
Hi,

Can you tell me what is the difference between two codes below:
Expand|Select|Wrap|Line Numbers
  1.     Set wdTable = wdDoc.Tables(2)
  2.     Set wdRange = wdTable.Range
  3.     wdRange.Collapse wdCollapseEnd
  4.     wdRange.Paste
--------------------------
Expand|Select|Wrap|Line Numbers
  1. wdDoc.Tables(2).Range.Collapse wdCollapseEnd
  2. wdDoc.Tables(2).Range.Paste
Why their behaviors not the same?
Dec 23 '08 #1
Share this Question
Share on Google+
3 Replies


Dököll
Expert 100+
P: 2,364
Greetings, markjavascript!

I have no idea; however adding to VBA for a closer look...

Hope you get this one nailed?;-)

In a bit!
Dec 31 '08 #2

NeoPa
Expert Mod 15k+
P: 31,186
Technically, the two sets of code appear similar to me. Obviously one is using object variables to reference the objects and the other references them specifically each time.

In general, these should be equivalent. However I can think of two issues which may effect this :
  1. Some objects only work properly when referenced via object variables. The only item I'm aware of though is CurrentDB in Access. Not familiar with MS Word environment but it's possible the same restrictions apply there for some objects.
  2. Your code snippet uses a Paste. If the two sets of code are run when different items are available on the clipboard, then you will have different results.
Perhaps, if you described exactly what results you're getting in each test we could be more help, although few of us are as expert in Word as we are in Access.

Welcome to Bytes!
Jan 12 '09 #3

NeoPa
Expert Mod 15k+
P: 31,186
Alternatively, consider using the "With" approach :
Expand|Select|Wrap|Line Numbers
  1. With wdDoc.Tables(2).Range
  2.   .Collapse wdCollapseEnd
  3.   .Paste
  4.   ...
  5. End With
This is both easier to develop and more efficient in execution.
Jan 12 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.