Autotext Trouble (Continuing)

S

Steve

I want to insert a simple table (2 row, 1 col) using AutoTextEntries.Insert,
move the cursor to the first cell and paste in a picture. The
Autotext.insert takes a long time to complete (maybe 1 second), but the
macro continues running before AutoTextEntries.Insert is completed. The
following lines that depend on having the new table object present then
fail. I've tried pausing the macro with the Sleep API call and DoEvents, but
that doesn't work. Any suggestions on how to fix this?
Thanks,
Steve

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

Sub SetTableDims()
Dim oHeight As Single
Dim oWidth As Single
Dim s As Shape
Dim oCell As Cell

NormalTemplate.AutoTextEntries("Insert Figure").Insert
Where:=Selection.Range
Doze (2000) ' Wait for insertion to complete

Selection.MoveUp Unit:=wdLine, Count:=2 ' Move to first cell of table

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

oHeight = Selection.Tables(1).Cell(1, 1).Range.InlineShapes(1).Height
'<-- Fails here with "Requested member

' of collection does not exist" because Table hasn't

' been inserted yet

' (AutoTextEntries("Insert Figure").Insert not complete)
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

Bye:
End Sub

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

DA

I'd try to capture the error with 'On Error', then show
the user a "Retry?" message box. This way you won't have
to use the sleep API call.
-----Original Message-----
I want to insert a simple table (2 row, 1 col) using AutoTextEntries.Insert,
move the cursor to the first cell and paste in a picture. The
Autotext.insert takes a long time to complete (maybe 1 second), but the
macro continues running before AutoTextEntries.Insert is completed. The
following lines that depend on having the new table object present then
fail. I've tried pausing the macro with the Sleep API call and DoEvents, but
that doesn't work. Any suggestions on how to fix this?
Thanks,
Steve

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

Sub SetTableDims()
Dim oHeight As Single
Dim oWidth As Single
Dim s As Shape
Dim oCell As Cell

NormalTemplate.AutoTextEntries("Insert Figure").Insert
Where:=Selection.Range
Doze (2000) ' Wait for insertion to complete

Selection.MoveUp Unit:=wdLine, Count:=2 ' Move to first cell of table

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

Steve

Thanks, but that's too kludgy.

I can't find solution to this problem, so I build the table with borders,
field entries, etc. on-the-fly.
 
P

Peter Hewett

Hi Steve

I've never heard of AutoText lagging behind in such a manner. I don't believe it to be
possible, it's at total variance to the way Word needs to work.

I'd breakpoint my code on the line that failing and make sure that the Selection object
contains what you think it does. Check that the Selection object actually contains a
Table. Tables is not the only collection object you are referencing. it could be the
InlineShapes collection that's throwing the error.

HTH + Cheers - Peter
 
S

Steve

Peter...it is indeed behaving that way. If I single-step through the code
and wait for the AutoTextEntry to complete, everything works fine. Word
takes ~1/2 second to insert the AutoTextEntry when I execute the
NormalTemplate.AutoTextEntries("Insert Figure").Insert
Where:=Selection.Range line.

Interestingly, if I insert the AutoText entry from within Word using the
menu, it is almost instantaneous.

When I run the macro (F5), the picture gets inserted below the table, not in
Cell 1. As a result, the "oHeight = " line fails because there is no picture
in Cell 1.

Try it yourself. Set up a 1-col, 2-row table AutoText entry and run the
code. I'd be interested in hearing if you have the same problem. I'm running
a 2 GHz Sony Vaio, 256 MB RAM, Office 2000.

I gave up on this approach today and now code the table and all its
properties directly instead of pulling them in from AutoText. I then
discovered that you can't directly select the last sentence in a table cell
(see "Selecting Last Sentence in a Table" message later on). If it's not one
thing, it's another.

Steve
 

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