Hi,
I am trying to create a macro which will search for space before comma and space before full stop (period).
If i check one condition at a time like , only it works perfectly fine. However when i apply or condition it does not work properly.
"If crn_txt <> "," Or crn_txt <> "." Then
If crn_txt = "," Or crn_txt <> "," And old_text = " " Then"
Given below is the code that i have prepared for reference. Checking one by one in loop like .(period) then comma it is taking lots of time.
Please help it is very important for me.
Sub spc_bfr_comma()
fnt_nme = False
fnt_clr = False
Dim oSld As Slide
Dim now_end As Boolean
Dim x As Long
Dim m As Double
Dim R As Double
shape_cont = 1
err_num = 0
now_end = False
slide_num = 1
m = 0
fnt_clr_chck = False
For Each oSld In ActivePresentation.Slides
With Application.ActiveWindow
ViewType = ppViewNormal
On Error Resume Next
.View.GotoSlide slide_num
End With
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
With oShp.TextFrame.TextRange
'For x = .Runs.Count To 1 Step -1
Text = .Runs(x).Text
On Error Resume Next
ActiveWindow.Selection.SlideRange.Shapes(shape_cont).Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
whole_text = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Text
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Words
whole_text_len = Len(whole_text)
'crn_txt = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=x). Characters
cnrvsn_text_dbl = CDbl(whole_text_len)
end_loop = cnrvsn_text_dbl
For k = 1 To end_loop
crn_txt = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(start:=k). Characters
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(start:=k). Select
If crn_txt <> "," Or crn_txt <> "." Then
old_text = Empty
End If
If crn_txt = "," Or crn_txt <> "," And old_text = " " Then
d = k - 1
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(start:=d). Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(start:=d). Cut
k = k - 5
'If k > end_loop Then
'shape_cont = shape_cont + 1
'GoTo a:
'Exit Sub
'End If
'MsgBox "Error"
old_text = Empty
crn_txt = Null
End If
If crn_txt = " " Then
old_text = crn_txt
End If
Next k
'Next x
End With
End If 'has text
End If 'has textframe
a:
shape_cont = shape_cont + 1
Next oShp
slide_num = slide_num + 1
shape_cont = 1
Next oSld
slide_num = 1
'period_chk
'MsgBox "SPACE BEFORE comma DONE"
'UserForm1.Visible = False
End Sub
Regards
Rathish