A
avkokin
Hello.
There is one document which has many pictures (embeded and linked).
Linked pictures has alternative texts. I want to create new document
and insert these alternative text from every picture to the table
within new document. I tried next macro (below), but I can't do good
work it. Please give me any tips.
Thank you.
My macro:
Sub extractAltText_to_NewDoc()
'
Dim alText As String
Dim nAltext As Long
Dim oShape As InlineShape
Dim oSec As Section
Dim oTable As Table
Dim i As Integer
Dim oRange As Range
Dim newDoc As Document
Dim actDoc As Document
Dim ptWidth As Single
Application.ScreenUpdating = False
Set newDoc = Documents.Add
With newDoc.PageSetup
ptWidth = PicasToPoints(51) - (.RightMargin + .LeftMargin)
End With
Set oTable = newDoc.Tables.Add(Selection.Range, nAltext + 1, 2)
With oTable
.Borders.Enable = True
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Rows.AllowBreakAcrossPages = False
.TopPadding = PicasToPoints(0.5)
.BottomPadding = PicasToPoints(0.5)
.Columns(1).PreferredWidth = ptWidth * 0.65
.Columns(2).PreferredWidth = ptWidth * 0.35
End With
With oTable.Cell(1, 1).Range
.Font.Name = "Arial"
.Font.Bold = True
.InsertAfter "Alternative text"
End With
With oTable.Cell(1, 2).Range
.Font.Name = "Arial"
.Font.Bold = True
.InsertAfter "Page number"
End With
For Each oSec In ActiveDocument.Sections
For Each oShape In ActiveDocument.InlineShapes
alText = oShape.AlternativeText
If oShape.Type = wdInlineShapeLinkedPicture And Len(alText)
<> 0 Then
nAltext = ActiveDocument.InlineShapes.Count
For i = 1 To nAltext
Application.StatusBar = "Add " & nAltext & " to table:
" & i
With oTable.Cell(i + 1, 1).Range
.Font.Name = "Arial"
.Font.Size = 11
.InsertAfter alText
End With
With oTable.Cell(i + 1, 2).Range
.Font.Name = "Arial"
.Font.Size = 14
.InsertAfter
CStr(Selection.Information(wdActiveEndPageNumber))
End With
Next i
ElseIf oShape.Type = wdInlineShapePicture Then
i = i + 1
End If
Next oShape
Next oSec
End Sub
There is one document which has many pictures (embeded and linked).
Linked pictures has alternative texts. I want to create new document
and insert these alternative text from every picture to the table
within new document. I tried next macro (below), but I can't do good
work it. Please give me any tips.
Thank you.
My macro:
Sub extractAltText_to_NewDoc()
'
Dim alText As String
Dim nAltext As Long
Dim oShape As InlineShape
Dim oSec As Section
Dim oTable As Table
Dim i As Integer
Dim oRange As Range
Dim newDoc As Document
Dim actDoc As Document
Dim ptWidth As Single
Application.ScreenUpdating = False
Set newDoc = Documents.Add
With newDoc.PageSetup
ptWidth = PicasToPoints(51) - (.RightMargin + .LeftMargin)
End With
Set oTable = newDoc.Tables.Add(Selection.Range, nAltext + 1, 2)
With oTable
.Borders.Enable = True
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Rows.AllowBreakAcrossPages = False
.TopPadding = PicasToPoints(0.5)
.BottomPadding = PicasToPoints(0.5)
.Columns(1).PreferredWidth = ptWidth * 0.65
.Columns(2).PreferredWidth = ptWidth * 0.35
End With
With oTable.Cell(1, 1).Range
.Font.Name = "Arial"
.Font.Bold = True
.InsertAfter "Alternative text"
End With
With oTable.Cell(1, 2).Range
.Font.Name = "Arial"
.Font.Bold = True
.InsertAfter "Page number"
End With
For Each oSec In ActiveDocument.Sections
For Each oShape In ActiveDocument.InlineShapes
alText = oShape.AlternativeText
If oShape.Type = wdInlineShapeLinkedPicture And Len(alText)
<> 0 Then
nAltext = ActiveDocument.InlineShapes.Count
For i = 1 To nAltext
Application.StatusBar = "Add " & nAltext & " to table:
" & i
With oTable.Cell(i + 1, 1).Range
.Font.Name = "Arial"
.Font.Size = 11
.InsertAfter alText
End With
With oTable.Cell(i + 1, 2).Range
.Font.Name = "Arial"
.Font.Size = 14
.InsertAfter
CStr(Selection.Information(wdActiveEndPageNumber))
End With
Next i
ElseIf oShape.Type = wdInlineShapePicture Then
i = i + 1
End If
Next oShape
Next oSec
End Sub