M
mlee
Hi Everyone,
One question before I ask my leading question. Does the Range feature
work with tables in a word document.
What I have. I've created a template file that contains one page with
a table. I'm simulating a Raffle ticket. There 4 rows with each row
representing a raffle ticket.
What I want to do. I want to be able to enter a number range in a VB6
form and use Word Automation to automatically increment the number you
would usually see in a raffle ticket. Since I can only fit 4 tickets
per page, I would like to increment the number until the end of the
page, add a new page (append the same template file to the end of the
document) and continue the numbers on the next page.
What I've done so far, but have problems.
Solution 1: The template file contains Bookmarks and I use code like
this:
For i = startCount To endCount
'Repeat for each bookmark
WordApp.ActiveDocument.Bookmarks("XXXX1").Select
WordApp.Selection.InsertAfter (Format(i, "00000"))
next i
'Not append template to end of this doc.
WordApp.Selection.InsertFile FilePath, , False
Comment: The appending of the template file to the end of the doc does
work, but since its the same template file I started with, when it
inserts the text, it starts on the first page and inserts the text to
the begenning of the first text that was inserted, instead of going to
the second page. Is there an easier way to do this.
Solution 2:
Same template file, but replaced the Bookmarks with text like this:
XXXXX1
XXXXX2
ect..
In this case I tried using the find method, but I always get VB6
blowing up on me. I have code like the following:
WordApp.Selection.HomeKey wdStory
Set rng = WordApp.Selection.Range
rng.Find.ClearFormatting
rng.Find.Replacement.ClearFormatting
rng.Find.Text = FindText
rng.Find.Replacement.Text = ReplaceText
rng.Find.Forward = True
rng.Find.Wrap = wdFindContinue
rng.Find.MatchCase = False
rng.Find.MatchWholeWord = False
FindReplace = rng.Find.Execute(Replace:=wdReplaceAll)
For one, for some reason when setting rng (the Range object) it never
gets set to anything. And vb blows up on the about the Clearformatting
method. I've tried so many different versions of this code, that its
making me sick looking at it, lol.
Please let me know if there a better way than the above solutions. Any
suggestions and examples would be great. Thanks.
Michael
One question before I ask my leading question. Does the Range feature
work with tables in a word document.
What I have. I've created a template file that contains one page with
a table. I'm simulating a Raffle ticket. There 4 rows with each row
representing a raffle ticket.
What I want to do. I want to be able to enter a number range in a VB6
form and use Word Automation to automatically increment the number you
would usually see in a raffle ticket. Since I can only fit 4 tickets
per page, I would like to increment the number until the end of the
page, add a new page (append the same template file to the end of the
document) and continue the numbers on the next page.
What I've done so far, but have problems.
Solution 1: The template file contains Bookmarks and I use code like
this:
For i = startCount To endCount
'Repeat for each bookmark
WordApp.ActiveDocument.Bookmarks("XXXX1").Select
WordApp.Selection.InsertAfter (Format(i, "00000"))
next i
'Not append template to end of this doc.
WordApp.Selection.InsertFile FilePath, , False
Comment: The appending of the template file to the end of the doc does
work, but since its the same template file I started with, when it
inserts the text, it starts on the first page and inserts the text to
the begenning of the first text that was inserted, instead of going to
the second page. Is there an easier way to do this.
Solution 2:
Same template file, but replaced the Bookmarks with text like this:
XXXXX1
XXXXX2
ect..
In this case I tried using the find method, but I always get VB6
blowing up on me. I have code like the following:
WordApp.Selection.HomeKey wdStory
Set rng = WordApp.Selection.Range
rng.Find.ClearFormatting
rng.Find.Replacement.ClearFormatting
rng.Find.Text = FindText
rng.Find.Replacement.Text = ReplaceText
rng.Find.Forward = True
rng.Find.Wrap = wdFindContinue
rng.Find.MatchCase = False
rng.Find.MatchWholeWord = False
FindReplace = rng.Find.Execute(Replace:=wdReplaceAll)
For one, for some reason when setting rng (the Range object) it never
gets set to anything. And vb blows up on the about the Clearformatting
method. I've tried so many different versions of this code, that its
making me sick looking at it, lol.
Please let me know if there a better way than the above solutions. Any
suggestions and examples would be great. Thanks.
Michael