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
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