ワードパッドの画像をExcelにコピー
ワードパッドしかない環境で仕方なく画面コピーをずらずら沢山とった後で、自分のPCでExcelにコピーしたい。そんなときのWordマクロ。
Excel Object Libraryの参照設定が必要。WordでALT+F11押してからツール→参照設定。
Dim ex As New Excel.Application Const picScale As Double = 0.8 Const numPageBreak As Integer = 2 Sub WordからExcelコピー() Dim sh1 As Worksheet, r As Word.Range, f As Field, doc As Document, rnum As Integer, npage As Integer Dim str As String ex.Visible = True Set doc = ActiveDocument Set sh1 = ex.Workbooks.Add().ActiveSheet rnum = 1 For Each r In doc.Words If r.InlineShapes.Count > 0 Then If npage > 1 And npage Mod numPageBreak = 0 Then sh1.HPageBreaks.Add sh1.Cells(rnum, 1) sh1.Cells(rnum, 1) = str str = "" rnum = rnum + 2 r.Copy sh1.Cells(rnum, 1).Select sh1.Paste ex.Selection.ShapeRange.ScaleHeight picScale, msoTrue rnum = rnum + ex.Selection.Height / sh1.Rows(rnum).RowHeight rnum = rnum + 3 npage = npage + 1 Else If Asc(r.Text) <> 12 Then str = str & r.Text 'Word側改ページ無視 End If Next End Sub