InsertAutotext is Slow

S

Steve

I'm storing a two-cell table in an AutoText entry. VBA inserts the table
from AutoText, moves the cursor up two lines, and pastes a graphic into Cell
1 from the clipboard. This works fine if step slowly through the code. When
I run the code, the PasteSpecial gets executed BEFORE the AutoText insertion
is completed and the cursor hasn't moved up two lines. As a result, the
graphic is pasted below the table. How do I make sure that the
AutoTextEntries().Insert is completed successfully before moving to the next
line of code?

Steve

Sub SetTableDims()
Dim oHeight As Single
Dim oWidth As Single

NormalTemplate.AutoTextEntries("Insert Figure").Insert _
Where:=Selection.Range

Selection.MoveUp Unit:=wdLine, Count:=2

Selection.PasteSpecial Link:=False, _
DataType:=wdPasteDeviceIndependentBitmap, _
Placement:=wdInLine, _
DisplayAsIcon:=False

oHeight = Selection.Tables(1).Cell(1, 1).Range.InlineShapes(1).Height
oWidth = Selection.Tables(1).Cell(1, 1).Range.InlineShapes(1).Width

Selection.Tables(1).Cell(1, 1).Height = oHeight
Selection.Tables(1).Columns(1).Width = oWidth

End Sub
 
G

Greg

Steve,

Peter Hewitt posted a method for instructing macros to
doze for a specdified time. Perhaps this would work for
you:

Private Declare Sub Sleep Lib "kernel32" (ByVal
dwMilliseconds As Long)

Private Sub Doze(ByVal lngPeriod As Long)
DoEvents
Sleep lngPeriod
End Sub

Call it at the appropriate point in your macro like this:

' (e.g., leep for 2 seconds)
Doze 2000
-----Original Message-----
I'm storing a two-cell table in an AutoText entry. VBA inserts the table
from AutoText, moves the cursor up two lines, and pastes a graphic into Cell
1 from the clipboard. This works fine if step slowly through the code. When
I run the code, the PasteSpecial gets executed BEFORE the AutoText insertion
is completed and the cursor hasn't moved up two lines. As a result, the
graphic is pasted below the table. How do I make sure that the
AutoTextEntries().Insert is completed successfully before moving to the next
line of code?

Steve

Sub SetTableDims()
Dim oHeight As Single
Dim oWidth As Single

NormalTemplate.AutoTextEntries("Insert Figure").Insert _
Where:=Selection.Range

Selection.MoveUp Unit:=wdLine, Count:=2

Selection.PasteSpecial Link:=False, _
DataType:=wdPasteDeviceIndependentBitmap, _
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top