|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 未忘初心 于 2019-2-27 17:51 编辑
- Sub Main()
- 'Date:2019/2/27 正月廿三 Wednesday
- '标签:word导出图片
- '备注:
- Dim DiaFile As FileDialog, i As Integer, wordPath As String
- Dim arr2(1 To 3000, 1 To 14)
- Dim wordApp As Object, wdDoc As Object, Table As Object
- Dim myshape As Object, k As Long
- Set DiaFile = Application.FileDialog(msoFileDialogFilePicker)
- With DiaFile
- .AllowMultiSelect = False
- .Filters.Clear
- .InitialFileName = ThisWorkbook.path
- .Filters.Add "word Files", "*.doc*"
- .Title = "请选择Word 文件"
- If .Show() = -1 Then
- wordPath = .SelectedItems(1)
- End If
- End With
- If Len(wordPath) > 0 Then
- Set wordApp = CreateObject("Word.Application")
- GetObject(wordPath).Close 0
- Set wdDoc = wordApp.Documents.Open(wordPath)
- For i = 1 To wdDoc.Tables.Count
- '----------------处理表格-----------------------------
- Set Table = wdDoc.Tables(i)
- k = k + 1
- arr2(i, 1) = Replace(Table.Cell(2, 2).Range.Text, Chr(13) & Chr(7), "") '姓名
- arr2(i, 2) = Replace(Table.Cell(2, 4).Range.Text, Chr(13) & Chr(7), "") '性别
- arr2(i, 3) = Replace(Table.Cell(3, 2).Range.Text, Chr(13) & Chr(7), "") '学籍号
- arr2(i, 4) = Replace(Table.Cell(3, 6).Range.Text, Chr(13) & Chr(7), "") '出生日期
- arr2(i, 5) = "'" & Replace(Table.Cell(4, 4).Range.Text, Chr(13) & Chr(7), "") 'sfz
- arr2(i, 6) = Replace(Table.Cell(5, 2).Range.Text, Chr(13) & Chr(7), "") '所在学校
- arr2(i, 7) = Replace(Table.Cell(6, 6).Range.Text, Chr(13) & Chr(7), "") '所在学校
- arr2(i, 8) = Replace(Table.Cell(7, 2).Range.Text, Chr(13) & Chr(7), "") '所在学校
- arr2(i, 9) = Replace(Table.Cell(10, 2).Tables(1).Cell(2, 2).Range.Text, Chr(13) & Chr(7), "")
- arr2(i, 10) = Replace(Table.Cell(10, 2).Tables(1).Cell(2, 3).Range.Text, Chr(13) & Chr(7), "")
- arr2(i, 11) = Replace(Table.Cell(10, 2).Tables(1).Cell(3, 2).Range.Text, Chr(13) & Chr(7), "")
- arr2(i, 12) = Replace(Table.Cell(10, 2).Tables(1).Cell(3, 3).Range.Text, Chr(13) & Chr(7), "")
- arr2(i, 13) = Replace(Table.Cell(13, 1).Range.Text, Chr(13) & Chr(7), "") '学籍变动时间
- arr2(i, 14) = Replace(Table.Cell(13, 2).Range.Text, Chr(13) & Chr(7), "") '学籍变动情况
- Set Table = Nothing
- '----------------处理图片-----------------------------
- Set myshape = wdDoc.InlineShapes(i)
- If myshape.Type = 3 Then
- myshape.Select
- Set myshape = myshape.ConvertToShape
- With myshape
- .ScaleHeight 1, True, msoScaleFromMiddle
- .ScaleWidth 1, True, msoScaleFromMiddle
- End With
- wdDoc.ActiveWindow.Selection.Copy
- With Sheet1.ChartObjects.Add(0, 0, myshape.Width, myshape.Height).Chart
- .Paste
- .Export wdDoc.path & "\提取后重命名的照片" & arr2(i, 3) & ".jpg"
- .Parent.Delete
- End With
- '还原
- Set myshape = myshape.ConvertToInlineShape
- With myshape
- .Height = 83.9
- .Width = 54.15
- End With
- End If
- Next
- wdDoc.Close 0
- wordApp.Quit
- Set wdDoc = Nothing
- Set wordApp = Nothing
- If k > 0 Then
- Sheet1.Range("A2").Resize(k, 14) = arr2
- MsgBox "完成"
- End If
- End If
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|