Gringoire
Board Regular
- Joined
- Nov 18, 2016
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
Hello guys,
I'm using VBA to fill a Word document (OD below) from an Excel sheet but the code is extremely slow.
Translating about 900 Excel rows lasts 200 seconds
for each string(s) to translate from Excel there are two cases:
The second case (the most frequent) needs about 0.2 sec each loop.
The User can't wait more than three minutes for each Sheet conversion.
Is there some way to make the code above faster?
Sorry for the maybe silly question but I'm not good at all with Word VBA.
thanks
I'm using VBA to fill a Word document (OD below) from an Excel sheet but the code is extremely slow.
Translating about 900 Excel rows lasts 200 seconds
for each string(s) to translate from Excel there are two cases:
- the Excel row is translated in simple word text
- the Excel row is translated in a row of a word table
VBA Code:
Select Case Range_DATI(i%, PrintFRM)
Case "TESTO" 'Case data to simple text
With OD.ActiveWindow.Selection
.InsertAfter (Range_DATI(i%, 2) & vbCr)
.Collapse wdCollapseEnd
End With
The second case (the most frequent) needs about 0.2 sec each loop.
VBA Code:
Case "DATA" 'CASE data to tab
dummy = TimeACode("s")
NumTab = OD.Tables.Count
If Range_DATI((i% - 1), PrintFRM) <> "DATA" Then 'Creating table if not existing
Crea_tabella_AIDA
NumTab = NumTab + 1
Else
OD.Tables.Item(NumTab).Rows.Add 'Add row if table already exists
End If
With OD.Tables.Item(NumTab) 'Filling the cells
RigaAttiva = OD.Tables.Item(NumTab).Rows.Count
.Cell(RigaAttiva, 1).Range.Text = Range_DATI(i%, 2)
.Cell(RigaAttiva, 2).Range.Text = Range_DATI(i%, 3)
.Cell(RigaAttiva, 3).Range.Text = Range_DATI(i%, 4)
OD.ActiveWindow.Selection.EndOf Unit:=wdTable
OD.ActiveWindow.Selection.MoveDown
End With
dummy = TimeACode("stop") 'Fino a qui
Case else
...
The User can't wait more than three minutes for each Sheet conversion.
Is there some way to make the code above faster?
Sorry for the maybe silly question but I'm not good at all with Word VBA.
thanks