troubleshooting Question

Problem converting Word VBA to VB10

Avatar of DRfishman
DRfishman asked on
Microsoft WordMicrosoft ApplicationsVisual Basic.NET
2 Comments1 Solution582 ViewsLast Modified:
I have this VBA code in a Word 2007 file that moved one character at a time through a document
and at each change in a Style it would insert a string before the letter of the changed style text.
The sting is just the name o the style. I have been tying to convert this code to an app using VB 2010 Express.
I have no problems opening the word file, but I can't find how to move one character at a time through the whole document, identity the end o the document, and return the name of the selected text's style.
Any help will be greatly appreciated!
Public Sub PlaceTags()
'This procedure will scan a document for Word Styles and 
'   place a layout process tag before each change in text 
'   styles.

Dim cStyle As Style

'Place the curse at the top of the document
Selection.HomeKey Unit:=wdStory

'Place the first tag at the top of the doc.
Selection.InsertBefore "<" & Selection.Style & ">"

'This var will contain the last Style of the previous Char
Set cStyle = Selection.Style

'Loop until you reach the bottom of the document
Do Until ActiveDocument.Bookmarks("\Sel").Start = _

    'Select the next Char
    Selection.MoveRight Unit:=wdCharacter, Count:=1, _
    'Check to see if the selection has no Style - Like images
    If Selection.Style <> "Normal" Then
        'Assign the right Tag
        If Selection.Style <> cStyle Then
          'Add the Tag
          Selection.InsertBefore "<" & Selection.Style & ">"
          'Move the selections to the next Char
          Selection.Move Unit:=wdCharacter, Count:=1
        End If
    End If
    'Set the new current Style
    Set cStyle = Selection.Style
    'Move to the next Char
    Selection.Move Unit:=wdCharacter, Count:=1

End Sub

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros