Reputation: 2176
I use this code to insert a picture from the clipboard:
Selection.PasteSpecial Link:=False, DataType:=wdPasteDeviceIndependentBitmap, Placement:=wdInLine, _
DisplayAsIcon:=False
This code is running well with Word 2007 but not with Word 2013. In W07 the picture is copied into the document, with W13 I only get a blank document.
I tried it without the DataType
(Selection.PasteSpecial Placement:=wdInLine
) but still the same.
The picture is correct in the clipboard as shown under "Insert"
How can I get it work? Thanks
Update code with selection:
Selection.EndKey Unit:=wdStory
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=2
Selection.Cells.SetWidth ColumnWidth:=CentimetersToPoints(11.5), RulerStyle:=wdAdjustNone
Selection.Rows.SpaceBetweenColumns = CentimetersToPoints(0.25)
Selection.Move Unit:=wdColumn, Count:=1
Selection.SelectColumn
Selection.Cells.SetWidth ColumnWidth:=CentimetersToPoints(4.5), RulerStyle:=wdAdjustNone
Selection.Rows.SpaceBetweenColumns = CentimetersToPoints(0.25)
Selection.SelectColumn
Selection.Cells.HeightRule = wdRowHeightAuto
With Selection.Rows
.Alignment = wdAlignRowLeft
.AllowBreakAcrossPages = True
.SetLeftIndent LeftIndent:=CentimetersToPoints(0), RulerStyle:=wdAdjustNone
End With
Selection.Tables(1).Select
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.PasteSpecial Link:=False, DataType:=wdPasteDeviceIndependentBitmap, Placement:=wdInLine, _
DisplayAsIcon:=False
Selection.MoveRight Unit:=wdCharacter, Count:=1
Upvotes: 0
Views: 1363
Reputation: 25663
The additional code helps - and I've edited it to use the Word object model instead of Selection. It should now execute faster, be more predictable and easier to read. What wasn't clear from your code is whether you want to change the column settings for the first or the second column and whether the picture should be in the first or the second cell. If I got it wrong, you can simply change the index numbers (from 1 to 2).
I changed the PasteSpecial to paste into the cell Range (rather than "to" the cell). It might help if the "target" doesn't not contain the cell's structural storage (end-of-cell marker). Give this a try...
Dim rngDoc as Word.Range, rngTbl as Word.Range
Dim tbl as Word.Table, col1 as Word.Column
Set rngDoc = ActiveDocument.Content
rngDoc.Collapse wdCollapseEnd 'End of the document
Set tbl = ActiveDocument.Tables.Add Range:=rngDoc, NumRows:=1, NumColumns:=2
Set rngTbl = tbl.Range
rngTbl.Cells.SetWidth ColumnWidth:=CentimetersToPoints(11.5),
RulerStyle:=wdAdjustNone
tbl.Rows.SpaceBetweenColumns = CentimetersToPoints(0.25)
tbl.Columns(1).Cells.SetWidth ColumnWidth:=CentimetersToPoints(4.5),
RulerStyle:=wdAdjustNone
tbl.Columns(1).Cells.HeightRule = wdRowHeightAuto
With tbl.Rows
.Alignment = wdAlignRowLeft
.AllowBreakAcrossPages = True
.SetLeftIndent LeftIndent:=CentimetersToPoints(0),
RulerStyle:=wdAdjustNone
End With
With tbl
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
End With
Set rng = tbl.Cell(1,1).Range
rng.Collapse wdCollapseStart
rng.PasteSpecial Link:=False, DataType:=wdPasteDeviceIndependentBitmap,
Placement:=wdInLine, DisplayAsIcon:=False
Upvotes: 1