D
Diman
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.
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