PDA

View Full Version : i'm wondering - What's wrong ???



baset
01-25-2016, 01:24 PM
I'm using the below macro:




Sub hhh()

Dim oSld As Slide
Dim oShp As Shape

On Error Resume Next

Set oSld = ActiveWindow.View.Slide

For Each oShp In oSld.Shapes

'-------------------------- Table --------------------------

If oShp.HasTable Then
Call r2LTable(oShp.Table)
End If
End Sub

Sub r2LTable(otbl As Table)
Dim iRow As Integer
Dim iCol As Integer
Dim L As Long

For iRow = 1 To otbl.Rows.Count
For iCol = 1 To otbl.Columns.Count
With otbl.Cell(iRow, iCol).Shape.TextFrame.TextRange
.Font.Name = "Arial"
.Font.NameComplexScript = "Arial"
.ParagraphFormat.TextDirection = ppDirectionRightToLeft
.RtlRun

If .ParagraphFormat.Alignment = ppAlignLeft Then
.ParagraphFormat.Alignment = ppAlignRight
End If

If CharType(.Characters(L)) = "English" Then
With .Characters(L)
.LanguageID = msoLanguageIDEnglishUS
End With
ElseIf CharType(.Characters(L)) = "Space" Then
'If CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" Then
With .Characters(L)
'.Font.Underline = -4119
.LanguageID = msoLanguageIDEnglishUS
End With
'End If
End If
Next L
End With
Next iCol
Next iRow
End Sub


It didn't work until i comment this line:

'If CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" Then

!!!!!!!!

any explanations ?







Private Function CharType(Letter As String) As String
Select Case AscW(Letter)

Case 32
CharType = "Space"
Case 48 To 57 '0-9
CharType = "English"
Case 65 To 90 'A-Z
CharType = "English"
Case 97 To 122 'a-z
CharType = "English"
Case 174 '®
CharType = "English"
Case 8482 '™
CharType = "English"
Case 169 '©
CharType = "English"
Case 44 ',
CharType = "English"
Case 64 '@
CharType = "English"
End Select
End Function

baset
01-25-2016, 01:26 PM
Here you are the file for test.

SamT
01-25-2016, 08:26 PM
Please edit your post to add CODE Tags.

John Wilson
01-26-2016, 12:20 AM
Probably because when L =1 you are checking Characters(zero)

baset
01-26-2016, 03:00 AM
Please edit your post to add CODE Tags.

Sorry SamT; How can i do that step ???

baset
01-26-2016, 03:02 AM
Probably because when L =1 you are checking Characters(zero)

I see that this code work properly on other tables not all; so if the case was like you thought can it be solved ??

SamT
01-26-2016, 07:19 AM
The Editor # Icon will insert CODE Tags in the Editor TextBox, then you can paste your code between them. Or you can Select the code, then click the Icon and the editor will place the code between the Tags. Finally, you can type the Tags where needed.

Use the "Edit Post" under your post to edit. If you don't see one there, let me know. I think it is on a time limit for Members.

baset
01-26-2016, 07:29 AM
The Editor # Icon will insert CODE Tags in the Editor TextBox, then you can paste your code between them. Or you can Select the code, then click the Icon and the editor will place the code between the Tags. Finally, you can type the Tags where needed.

Use the "Edit Post" under your post to edit. If you don't see one there, let me know. I think it is on a time limit for Members.

Thanks SamT for your advise; Kindly note that i don't have "Edit Post" option.

John Wilson
01-26-2016, 07:29 AM
Characters(zero) will always throw an error. You have On Error Resume Next set which will hide the error but may act on it in unpredictable ways.. Alter the code so (L-1) cannot equal zero of if it does that line is ignored

Paul_Hossler
01-26-2016, 07:51 AM
Thanks SamT for your advise; Kindly note that i don't have "Edit Post" option.


There's some sort of time out window, after which you can't edit the post -- I think the moderators can (not sure)

When you're within the window, you get another button that allows you to edit the post.

I usually have to do that since my keyboard insists on making spelling mistakes which I don't catch until I post it (even with preview)


15286

baset
01-26-2016, 08:06 AM
There's some sort of time out window, after which you can't edit the post -- I think the moderators can (not sure)

When you're within the window, you get another button that allows you to edit the post.

I usually have to do that since my keyboard insists on making spelling mistakes which I don't catch until I post it (even with preview)


15286

Unfortunattely i don't have this command available:

15288

baset
01-26-2016, 08:34 AM
Characters(zero) will always throw an error. You have On Error Resume Next set which will hide the error but may act on it in unpredictable ways.. Alter the code so (L-1) cannot equal zero of if it does that line is ignored

Dear John

How can i do that step ???

baset
01-26-2016, 08:55 AM
Dear John

How can i do that step ???

this is what i did but not working:


ElseIf CharType(.Characters(L)) = "Space" Or CharType(.Characters(L)) = "Dash" _
Or CharType(.Characters(L)) = "Dot" Or CharType(.Characters(L)) = "Underscore" Then

'If CharType(.Characters(L - 1)) <> False Then
If CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" _
And CharType(.Characters(L - 1)) <> False Then


With .Characters(L)
'.Font.Underline = -4119
.LanguageID = msoLanguageIDEnglishUS
End With
End If
'End If

baset
01-26-2016, 09:47 AM
Dear John

This is another approach but also not working:


For L = 1 To .Characters.Count If CharType(.Characters(L)) = "English" Then
With .Characters(L)
.LanguageID = msoLanguageIDEnglishUS
End With
End If

If CharType(.Characters(L)) = "Space" Or CharType(.Characters(L)) = "Dash" _
Or CharType(.Characters(L)) = "Dot" Or CharType(.Characters(L)) = "Underscore" Then
If CharType(.Characters(L - 1)) = "Null" Then
.Characters(L - 1) = L
ElseIf CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" Then
With .Characters(L)
'.Font.Underline = -4119
.LanguageID = msoLanguageIDEnglishUS
End With
End If
End If
Next L

SamT
01-26-2016, 12:10 PM
If L-1 > O Then
If CharType(.Characters(L - 1)) = "Null" Then
.Characters(L - 1) = L
ElseIf CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" Then
With .Characters(L)
'.Font.Underline = -4119
.LanguageID = msoLanguageIDEnglishUS
End With
End If
End If

baset
01-26-2016, 01:07 PM
I noticed that the 1st part of the macro runs on all items inside the group while the 2nd one runs only on the first item and ignored the rest item; any explanations ???


For ooo = 1 To ogrp.GroupItems.Count Set oTxtRng = ogrp.GroupItems(ooo).TextFrame.TextRange
With oTxtRng


.Font.Name = "Arial"
.Font.NameComplexScript = "Arial"
.ParagraphFormat.TextDirection = ppDirectionRightToLeft
.RtlRun
If .ParagraphFormat.Alignment = ppAlignLeft Then
.ParagraphFormat.Alignment = ppAlignRight
End If




End With
Next ooo



For ooo = 1 To ogrp.GroupItems.Count Set oTxtRng = ogrp.GroupItems(ooo).TextFrame.TextRange
With oTxtRng


For L = 1 To .Characters.Count
If CharType(.Characters(L)) = "English" Then
With .Characters(L)
.LanguageID = msoLanguageIDEnglishUS
End With

ElseIf CharType(.Characters(L)) = "Space" Or CharType(.Characters(L)) = "Dash" _
Or CharType(.Characters(L)) = "Dot" Or CharType(.Characters(L)) = "Underscore" Then
If CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" Then
With .Characters(L)
'.Font.Underline = -4119
.LanguageID = msoLanguageIDEnglishUS
End With
End If
End If
Next L




End With
Next ooo

baset
01-26-2016, 01:28 PM
If L-1 > O Then
If CharType(.Characters(L - 1)) = "Null" Then
.Characters(L - 1) = L
ElseIf CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" Then
With .Characters(L)
'.Font.Underline = -4119
.LanguageID = msoLanguageIDEnglishUS
End With
End If
End If


Dear SamT

Thanks for trying to help here; i used your code as shown below but still the same problem exist:


For L = 1 To .Characters.Count
If CharType(.Characters(L)) = "English" Then
With .Characters(L)
.LanguageID = msoLanguageIDEnglishUS
End With

ElseIf CharType(.Characters(L)) = "Space" Then
If L - 1 > 0 Then
If CharType(.Characters(L - 1)) = "Null" Then
.Characters(L - 1) = L
ElseIf CharType(.Characters(L - 1)) = "English" And CharType(.Characters(L + 1)) = "English" Then
With .Characters(L)
'.Font.Underline = -4119
.LanguageID = msoLanguageIDEnglishUS
End With
End If
End If
End If
Next L

baset
02-01-2016, 09:07 AM
Dear John


You said "Probably because when L =1 you are checking Characters(zero)"


Then said "Characters(zero) will always throw an error. You have On Error Resume Next set which will hide the error but may act on it in unpredictable ways.. Alter the code so (L-1) cannot equal zero of if it does that line is ignored"


How can make sure that this is the reason of this fault; for example using a code like this:



If CharType(.Characters(L + 1)) = "Null" Then
MsgBox ("Baset" & L)
End If

SamT
02-01-2016, 10:28 AM
If L > 1 Then
If CharType(.Characters(L - 1)) = "Null" Then
MsgBox ("Baset" & L - 1)
End If
Else 'L - 1 = 0
End If