A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Microsoft Word Help
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Problem with setting the value of DOCVARIABLE



 
 
Thread Tools Display Modes
  #1  
Old September 20th 18, 05:09 PM
Amanda Allen Amanda Allen is offline
Junior Member
 
First recorded activity by WordBanter: Oct 2014
Posts: 1
Default Problem with setting the value of DOCVARIABLE

I have a word project that I'm working on in which items are copied from an excel sheet into word using Selection.PasteAndFormat (wdFormatPlainText).
This is a list for a Table of Contents which only has dates (i.e. January 7 - 13, 1999) and a week number.
What I am trying to do is to get the dates and put them into a corresponding Week variable (one that has the dates) that will be in the title line of corresponding pages (52 or 53 pages).

I use the following code:
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
ActiveDocument.Variables("Week01").Value = Left(Selection.Text, InStr(Selection.Text, vbTab))
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
ActiveDocument.Variables("Week02").Value = Left(Selection.Text, InStr(Selection.Text, vbTab))
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
ActiveDocument.Variables("Week03").Value = Left(Selection.Text, InStr(Selection.Text, vbTab))
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine

This code gets the first 2 variables ok, but then starts to skip lines. (ie, week 3 would actually have week 4 value, week 4 would have week 5, week 5 would have week 7)

What an I doing wrong?
Is there a better way to do this?

Any help would be appreciated.
Ads
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DocVariable Paul Mailmerge 2 December 1st 09 08:55 PM
docvariable, template (.dot) Paul Mailmerge 2 October 7th 09 08:56 PM
Registry Policy Setting - Problem Changing Setting JenniferS30 Microsoft Word Help 1 January 14th 08 09:20 PM
Help with FIELD CODES: DOCVARIABLE!!! Wendy D Microsoft Word Help 2 August 16th 05 08:32 PM
Cannot printing DocVariable Field lubo Microsoft Word Help 1 April 9th 05 07:00 AM


All times are GMT +1. The time now is 11:20 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2004-2018 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.