I am new to VBA Macro programming. I need help to accomplish requirement.I have created a .Dotm file and deployed at startup folder of word.
My requirement is to copy the text between the two text range including range.
Because i don't have enough reputation i can't upload image. Example is given in below URL.
So i want to select the text between |{1A4F7D93-AD10-E411-9403-00155D101201}| highlighted red in image.
I have written below macro code to achieve the requirement. it is working fine upto certain extent but it adds extra page and sometime ignores Guid at the end. I think below code causes issue. I have specified count to 12. Selection.MoveRight Unit:=wdWord, Count:=12, Extend:=wdExtend
Dim lGuid As String lGuid = "{1A4F7D93-AD10-E411-9403-00155D101201}"
Dim tmpDoc As Document
Set tmpDoc =New DocumentSet tmpDoc = Documents.Add(Visible:=False)
tmpDoc.Paragraphs(1).Range.Delete
ActiveDocument.Select
Selection.WholeStory
Selection.Copy
Selection.HomeKey
tmpDoc.Select
Selection.WholeStory
Selection.PasteAndFormat wdFormatOriginalFormatting
Set myRange = tmpDoc.Range
firstTerm ="|"& lGuid &"|"
secondTerm ="|"& lGuid &"|"With myRange.Find
.Text = firstTerm.MatchWholeWord =True.Execute
myRange.Collapse direction:=wdCollapseEnd
Set selRange = tmpDoc.Range
selRange.Start = myRange.End.Text = secondTerm
.MatchWholeWord =True.Execute
myRange.Collapse direction:=wdCollapseStart
selRange.End= myRange.Start
selectedText = selRange.Select
Selection.MoveStart Unit:=wdLine, Count:=-1
Selection.MoveRight Unit:=wdWord, Count:=12, Extend:=wdExtend
Selection.Copy
EndWith
Dim workingDocument As DocumentSet workingDocument =New DocumentSet workingDocument = Documents.Add(Visible:=False)
workingDocument.Paragraphs(1).Range.Delete
workingDocument.Range.PasteAndFormat wdFormatOriginalFormatting
My requirement is to copy the text between the two text range including range.
Because i don't have enough reputation i can't upload image. Example is given in below URL.
So i want to select the text between |{1A4F7D93-AD10-E411-9403-00155D101201}| highlighted red in image.
I have written below macro code to achieve the requirement. it is working fine upto certain extent but it adds extra page and sometime ignores Guid at the end. I think below code causes issue. I have specified count to 12. Selection.MoveRight Unit:=wdWord, Count:=12, Extend:=wdExtend
Dim lGuid As String lGuid = "{1A4F7D93-AD10-E411-9403-00155D101201}"
Dim tmpDoc As Document
Set tmpDoc =New DocumentSet tmpDoc = Documents.Add(Visible:=False)
tmpDoc.Paragraphs(1).Range.Delete
ActiveDocument.Select
Selection.WholeStory
Selection.Copy
Selection.HomeKey
tmpDoc.Select
Selection.WholeStory
Selection.PasteAndFormat wdFormatOriginalFormatting
Set myRange = tmpDoc.Range
firstTerm ="|"& lGuid &"|"
secondTerm ="|"& lGuid &"|"With myRange.Find
.Text = firstTerm.MatchWholeWord =True.Execute
myRange.Collapse direction:=wdCollapseEnd
Set selRange = tmpDoc.Range
selRange.Start = myRange.End.Text = secondTerm
.MatchWholeWord =True.Execute
myRange.Collapse direction:=wdCollapseStart
selRange.End= myRange.Start
selectedText = selRange.Select
Selection.MoveStart Unit:=wdLine, Count:=-1
Selection.MoveRight Unit:=wdWord, Count:=12, Extend:=wdExtend
Selection.Copy
EndWith
Dim workingDocument As DocumentSet workingDocument =New DocumentSet workingDocument = Documents.Add(Visible:=False)
workingDocument.Paragraphs(1).Range.Delete
workingDocument.Range.PasteAndFormat wdFormatOriginalFormatting