ms word - VBA: Range.Find nested in another Range.Find -


in code, i'm splitting word document many using range.find select body of text (startoftext*endoftext) , saving it. within selected body of text, i'm trying use nested 'range.find' call search selected body of text bolded header , use saveas[filename].

with current code, works except nested range.text returns text within initial set range.

sub docsplitter()  dim r range dim inr range set r = activedocument.range.duplicate dim name string application.screenupdating = false  r.find     .text = "^m*^l^t^l" ' <- copies text ^m "^l^t^l"     .matchwildcards = true     while .execute         set inr = r.duplicate '<- setting range equal selected text range         inr.find             .format = true             .font.bold = true             .text = "^13([0-9]).([0-9])*^13^13" '<- selecting header within             .matchwildcards = true             .execute         end         copyandsave r, inr     wend end r.collapse wdcollapseend r.end = r.parent.range.end copyandsave r, inr  end sub     static sub copyandsave(r range, inr range) dim d document dim count long count = count + 1 r.copy set d = documents.add d.range.pasteandformat wdformatoriginalformatting d.saveas r.parent.path & application.pathseparator & _ inr.text, wdformatfilteredhtml '<-- file name error: long d.close  end sub 

so inr.text returns entire text selected r.find.execute. ideas?

edit: updated set inr = r.duplicate, catch. problem turned out formatting issue headers.

when set 1 range range both objects point exact same thing. different else use in vba, second object becomes independant copy of first.

in order create second range based on another, independent of need theduplicate property. so:

set inr = r.duplicate 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo