-
Using Word commands through an Excel macro
Hey all,
I am working on a project that requires a macro to run in Excel, open a Word document, and copy a specific selection [which is being found through a crude
search] of that document to another document. The problem I am having is in the copying part. I am trying to use commands that work when run as a Word macro (eg, Selection.Information (wdFirstCharacterLineNumber) and ActiveDocument.Range(0, Selection.Paragraphs(1).Range.End).Paragraphs.Count ), yet each one gives an error when run through Excel. Anyone have any idea how to get this to work? Here is the code:
Sub testsearch4()
Dim intX As Integer, intY As Integer, intZ As Range
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[EA]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
X = ActiveDocument.Range(0, Selection.Paragraphs(1).Range.End).Paragraphs.Count
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[/EA]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Y = ActiveDocument.Range(0, Selection.Paragraphs(1).Range.End).Paragraphs.Count
Set myRange = ActiveDocument.Range( _
Start:=ActiveDocument.Paragraphs(X + 1).Range.Start, _
End:=ActiveDocument.Paragraphs(Y - 1).Range.End)
myRange.Select
Selection.Copy
ActiveWindow.Close
Windows("MyTest.doc").Activate
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Selection.Paste
ActiveDocument.Save
End Sub
This works in Office 2000. Thank you for your help
-
Sounds like you need to add a reference to the Word object model in your Excel project: TOOLS menu, REFERENCES, select "Microsoft Word version number Object Library" and click OK.
-Andrew
Similar Threads
-
By namella in forum Mobile
Replies: 0
Last Post: 08-25-2005, 07:27 AM
-
By namella in forum VB Classic
Replies: 0
Last Post: 08-20-2005, 01:46 AM
-
By Werner in forum VB Classic
Replies: 2
Last Post: 06-15-2005, 02:13 PM
-
By VAX in forum VB Classic
Replies: 4
Last Post: 10-12-2000, 09:46 AM
-
By VAX in forum VB Classic
Replies: 0
Last Post: 10-10-2000, 11:52 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|