|
要实现的功能:使excel对应单元格,内容为word中宏运行出来的text1
已经测试,在word中的宏可以正常运行得到的这个text1
word宏代码如下:
Public Sub 选定文本66()
Dim begin1, end1, c As Long, i As Long, text1 As String
i = 1
Do
begin1 = "7.4.1 基金基本情况" & chr(13)
With Selection.Find
.Text = begin1
.Replacement.Text = ""
.Forward = True
End With
Selection.Find.Execute
a = Selection.Start
'选中截止的位置
end1 = "7.4.2 会计报表的编制基础" & chr(13)
With Selection.Find
.Text = end1
End With
Selection.Find.Execute
b = Selection.Start
ActiveDocument.Range(Start:=a, End:=b).Select
c = Selection.Paragraphs.Count
'ThisDocument.Activate
If i < c + 1 Then
Selection.Paragraphs(i).Range.Select
text1 = text1 & chr(13) & Selection.Text
i = i + 1
Else
'Debug.Print text1
End If
Loop Until i > c
End Sub
在excel中录制的如下,在excel中用这个代码调动word中的宏,并且想让excel的单元格内,文本为宏运行出来的文本。
Public Sub zwycopypaste()
Dim act As String
Dim mypath As String
Dim folder$
Dim wddoc As Object
Dim wdapp As Object
act = ThisWorkbook.Name
folder = ThisWorkbook.Path
mypath = Dir(folder & "\*.docx")
m = 1
Do While mypath <> ""
m = m + 1
Set wdapp = CreateObject("word.application")
Set wddoc = wdapp.documents.Open(folder & "\" & mypath)
wdapp.Visible = True
wdapp.Run "选定文本66"
wddoc.Close
wdapp.Quit
Set wddoc = Nothing
Set wdapp = Nothing
Workbooks(act).Sheets(1).Activate
ActiveSheet.Cells(m, 1).Value = abc
ActiveSheet.Cells(m, 2).Value = Left(mypath, Len(mypath) - 5)
mypath = Dir()
Loop
End
MsgBox "done"
End Sub
问题实质:
在word中的宏运行结束后,宏中的文本消失了,我想要把这个文本text1保存下来,使之可以在excel中被用到。
请问这个能怎么实现呢?谢谢各位朋友!
|
|