I need to add about 200 TextBox Shapes to a document through Visual
Basic using Word 9.0 Library

The Code i use is:
Set textBox22 = wordDoc.Shapes.AddTextbox(msoTextOrientationHorizontal,
10, y, 100, 15)

Then i add formatting:

With textBox22
.Name = "TextBox" & i
With .TextFrame
.MarginTop = 0
.MarginLeft = 0
.TextRange = "sdfgsf"
With .TextRange
.Bold = True
.Font.Name = "Verdana"
.Font.Size = 12
End With
End With
End With

This all works like a charm... except it works SLOOOOOOOW

The first 30 or so controls are added at a reasonable speed (i have a
counter and a progressbar to monitor the process)
After that it starts to slow down more and more....
On textbox 150 it adds about one textbox per second... Very Slow!!!!!

I tried following:
Turned off spelling and grammar checking, Word app is not visible while
textboxes are added, I even used LockWindowUpdate TOGETHER with
ScreenUpdating = False. Didn't help. Still slow....

Here's the code for you to try. Visual Basic 6.0. Add a reference to
the Word library before running the code. Add a progressbar to Form1
and name it PB1.

The code adds 300 textboxes to a word document and sets margins and
font format options. if you comment the formatting (all With..End With)
the code runs faster.


P.S. I HAVE tried it on different computers, and no they were not 486,
but decent p4 machines. And it must be done from outside, thus i can't
use the code from within a word macro.


[CODE]

Dim wA As Word.Application
Dim wD As Word.Document




Private Sub Command1_Click()

PB1.Min = 1 'PROGRESSBAR
PB1.Max = 300

Dim ttt As Word.Shape, y As Long
y = 10

wA.ScreenUpdating = False

For i = 1 To 300
PB1.Value = i
y = y + 18

Set tB = wD.Shapes.AddTextbox(msoTextOrientationHorizontal, 10,
y, 100, 15)

With tB
.Name = "TextBox" & i
With .TextFrame
.MarginTop = 0
.MarginLeft = 0
.TextRange = "Sample Text"
With .TextRange
.Bold = True
.Font.Name = "Verdana"
.Font.Size = 12
End With
End With
End With
Next

wA.ScreenUpdating = True

wA.Visible = True
End Sub





Private Sub Form_Load()
Set wA = New Word.Application

wA.Options.CheckGrammarAsYouType = False
wA.Options.CheckGrammarWithSpelling = False
wA.Options.CheckSpellingAsYouType = False
wA.Options.CheckHangulEndings = False
'wA.Options.Pagination = False

Set wD = wA.Documents.Add
wD.Activate
wD.ShowSpellingErrors = False
wD.ShowGrammaticalErrors = False

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
wA.Quit wdDoNotSaveChanges

End Sub

Re: Adding TextBox Shapes becomes slow by Jezebel

Jezebel
Sun Feb 20 15:59:29 CST 2005

Might be more useful to explain what you're actually trying to do. Why not
just do it once and save as a template?


"Diman" <diman1@hotpop.com> wrote in message
news:1108936245.539071.187400@c13g2000cwb.googlegroups.com...
>I need to add about 200 TextBox Shapes to a document through Visual
> Basic using Word 9.0 Library
>
> The Code i use is:
> Set textBox22 = wordDoc.Shapes.AddTextbox(msoTextOrientationHorizontal,
> 10, y, 100, 15)
>
> Then i add formatting:
>
> With textBox22
> .Name = "TextBox" & i
> With .TextFrame
> .MarginTop = 0
> .MarginLeft = 0
> .TextRange = "sdfgsf"
> With .TextRange
> .Bold = True
> .Font.Name = "Verdana"
> .Font.Size = 12
> End With
> End With
> End With
>
> This all works like a charm... except it works SLOOOOOOOW
>
> The first 30 or so controls are added at a reasonable speed (i have a
> counter and a progressbar to monitor the process)
> After that it starts to slow down more and more....
> On textbox 150 it adds about one textbox per second... Very Slow!!!!!
>
> I tried following:
> Turned off spelling and grammar checking, Word app is not visible while
> textboxes are added, I even used LockWindowUpdate TOGETHER with
> ScreenUpdating = False. Didn't help. Still slow....
>
> Here's the code for you to try. Visual Basic 6.0. Add a reference to
> the Word library before running the code. Add a progressbar to Form1
> and name it PB1.
>
> The code adds 300 textboxes to a word document and sets margins and
> font format options. if you comment the formatting (all With..End With)
> the code runs faster.
>
>
> P.S. I HAVE tried it on different computers, and no they were not 486,
> but decent p4 machines. And it must be done from outside, thus i can't
> use the code from within a word macro.
>
>
> [CODE]
>
> Dim wA As Word.Application
> Dim wD As Word.Document
>
>
>
>
> Private Sub Command1_Click()
>
> PB1.Min = 1 'PROGRESSBAR
> PB1.Max = 300
>
> Dim ttt As Word.Shape, y As Long
> y = 10
>
> wA.ScreenUpdating = False
>
> For i = 1 To 300
> PB1.Value = i
> y = y + 18
>
> Set tB = wD.Shapes.AddTextbox(msoTextOrientationHorizontal, 10,
> y, 100, 15)
>
> With tB
> .Name = "TextBox" & i
> With .TextFrame
> .MarginTop = 0
> .MarginLeft = 0
> .TextRange = "Sample Text"
> With .TextRange
> .Bold = True
> .Font.Name = "Verdana"
> .Font.Size = 12
> End With
> End With
> End With
> Next
>
> wA.ScreenUpdating = True
>
> wA.Visible = True
> End Sub
>
>
>
>
>
> Private Sub Form_Load()
> Set wA = New Word.Application
>
> wA.Options.CheckGrammarAsYouType = False
> wA.Options.CheckGrammarWithSpelling = False
> wA.Options.CheckSpellingAsYouType = False
> wA.Options.CheckHangulEndings = False
> 'wA.Options.Pagination = False
>
> Set wD = wA.Documents.Add
> wD.Activate
> wD.ShowSpellingErrors = False
> wD.ShowGrammaticalErrors = False
>
> End Sub
>
> Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
> On Error Resume Next
> wA.Quit wdDoNotSaveChanges
>
> End Sub
>



Re: Adding TextBox Shapes becomes slow by Diman

Diman
Mon Feb 21 03:31:45 CST 2005

I'm building this word document with a different number of textboxes
each time.. depending on data i receive from network. Even formatting
may differ, so a template is not an option.
But WHY does it slow down like hell after a while... That's what i
want to know... not suggestions on other workarounds.
Thanks anyway


Re: Adding TextBox Shapes becomes slow by Jezebel

Jezebel
Mon Feb 21 04:15:28 CST 2005

Given that your current method is, on your own account, unworkable, an
alternative method is precisely what you DO want. Why bother diagnosing what
doesn't work?




"Diman" <diman1@hotpop.com> wrote in message
news:1108978305.071641.190540@f14g2000cwb.googlegroups.com...
> I'm building this word document with a different number of textboxes
> each time.. depending on data i receive from network. Even formatting
> may differ, so a template is not an option.
> But WHY does it slow down like hell after a while... That's what i
> want to know... not suggestions on other workarounds.
> Thanks anyway
>



Re: Adding TextBox Shapes becomes slow by Diman

Diman
Mon Feb 21 05:02:41 CST 2005

As soon as i remove formatting, everything goes very fast again, but i
must have formatting... (font, font.size, fill.forecolor etc).

I'm tearing my hear out......


Re: Adding TextBox Shapes becomes slow by Diman

Diman
Mon Feb 21 10:14:31 CST 2005


Jezebel wrote:
> Might be more useful to explain what you're actually trying to do.
Why not
> just do it once and save as a template?
>
>
> "Diman" <diman1@hotpop.com> wrote in message
> news:1108936245.539071.187400@c13g2000cwb.googlegroups.com...




i'm creating a document based on data from network, so i can't use
templates, because the number of textboxes and their formatting may
vary from time to time


Re: Adding TextBox Shapes becomes slow by Jezebel

Jezebel
Mon Feb 21 14:51:44 CST 2005


>
>
> i'm creating a document based on data from network, so i can't use
> templates, because the number of textboxes and their formatting may
> vary from time to time

That's not a reason not to use a template. However, you seem committed to
your existing, malfunctioning method ...



Re: Adding TextBox Shapes becomes slow by strazz

strazz
Sun Feb 27 20:01:58 CST 2005

"Diman" <diman1@hotpop.com> wrote in message news:<1108983761.634845.127250@o13g2000cwo.googlegroups.com>...
> As soon as i remove formatting, everything goes very fast again, but i
> must have formatting... (font, font.size, fill.forecolor etc).
>
> I'm tearing my hear out......

You could consider storing an iteration of the paragraph or line which
contains the textboxes as an autotext entry and then insert this as
many times as needed.

I'm not saying it will be faster, but it may be worth a try.

Cheers
TonyS.