PDA

View Full Version : help to add enter after every superscript



cinnamoroll
10-27-2015, 09:03 PM
hi all, is there any ways or macro to allow me to enter after every superscript.
thanks.

gmayor
10-27-2015, 11:02 PM
Undoubtedly, but you will have to explain in greater detail what it is that you wish to achieve.

cinnamoroll
10-27-2015, 11:18 PM
Undoubtedly, but you will have to explain in greater detail what it is that you wish to achieve.

hi, thanks for the reply. what i wish to achieve is just after every superscript found in this word file, there will be an "enter" to the next line. example: 13^th abcdef will be shown as 13^th [enter] abcdef

thanks.

gmaxey
10-28-2015, 04:52 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.Superscript = True
While .Execute
oRng.Collapse wdCollapseEnd
While oRng.Characters.First = " "
oRng.Characters.First.Delete
Wend
oRng.InsertBefore vbCr
Wend
End With
lbl_Exit:
Exit Sub
End Sub

cinnamoroll
10-28-2015, 10:13 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.Superscript = True
While .Execute
oRng.Collapse wdCollapseEnd
While oRng.Characters.First = " "
oRng.Characters.First.Delete
Wend
oRng.InsertBefore vbCr
Wend
End With
lbl_Exit:
Exit Sub
End Sub


hi, thanks for the fast revert. its working but after running, my word document will hang/not responding.
any advice for this?

many thanks.

gmayor
10-28-2015, 11:07 PM
There is nothing in the macro that would cause the document to hang, but we have not seen what else lurks in your document. I personally would do it ever so slightly differently, but the result should be the same (with no document hanging).


Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.Superscript = True
While .Execute
oRng.Collapse wdCollapseEnd
While oRng.Characters.First = " "
oRng.Characters.First.Delete
Wend
oRng.Text = vbCr
oRng.Collapse wdCollapseEnd
Wend
End With
lbl_Exit:
Exit Sub
End Sub

cinnamoroll
10-28-2015, 11:11 PM
i have tried numerous times. it runs correctly but it just not responding and end up i have to restart the workbook, unable to save.

update: i tried to debug it and it keep looping below code, thus causing the document to be not responding. do i have to add in a code for .Font.Superscript = false? thanks.

While .Execute
oRng.Collapse wdCollapseEnd
While oRng.Characters.First = " "
oRng.Characters.First.Delete
Wend
oRng.Text = vbCr
oRng.Collapse wdCollapseEnd

gmaxey
10-29-2015, 04:49 AM
If not displaye, show non-printing characters (Ctrl+Shift+8) and ensure that there is only one paragraph mark at the end of the document and that it is not superscripted. That is the only thing I can think of to cause a loop.

gmayor
10-29-2015, 05:21 AM
i have tried numerous times. it runs correctly but it just not responding and end up i have to restart the workbook, unable to save.Workbook? This is a Word forum and a Word macro? What EXACTLY are you doing and where does Excel come into it?

cinnamoroll
10-29-2015, 08:44 PM
Workbook? This is a Word forum and a Word macro? What EXACTLY are you doing and where does Excel come into it?

sorry for the wrong usage of words. i meant word document.