PDA

View Full Version : macro to run shortcut



Ethen5155
04-16-2016, 02:58 AM
Hi all,


simply i was thinking are there anyway to create a macro that can help to run other macro assigned to shortcut (in MS word)


for ex.


i assigned (LTR Run) command to (CTRL+Shift+9) so i need a macro to go through all numbers only on file then do this shortcut (CTRL+Shift+9)


15939

is it possible??




Thanks

gmayor
04-16-2016, 04:54 AM
What do you mean by
so i need a macro to go through all numbers only on file

Ethen5155
04-16-2016, 05:05 AM
i mean that i want the LTR run command that was assigned to shortcut (CTRL+Shift+9) to be applied on numbers only,

in other words i want macro select all numbers on file then do (CTRL+Shift+9)..

gmayor
04-17-2016, 01:13 AM
Your requirement assumes that we have some inkling as to what you are trying to achieve. We cannot make guesses from LTR because we don't know what that does, nor do we know what numbers you are talking about. What 'file'? The open document? All the documents in a folder? All the documents on your hard drive? What numbers? Any number? Numbers that are not parts of dates? etc.

Ethen5155
04-17-2016, 01:37 AM
Dear Graham,

i have attached a sample doc file that i'm working on,

as you see on file english words and all digits took wrong order because i did (CTRL+A) to all file and do RTL run to all arabic text

and i assigned LTR command to the shortcut i mentioned (CTRL+SHIFT+9) then i have to go through the files and select digits and english words to give them LTR command to be on right order and English proofing language too


so i'm asking if it possible to select all digits and english words on file then do the shortcut that belongs to LTR command

or we can do a macro to do that step directly which is select all digits and english words then give them LTR command


i hope you got it and help me about that because i need this case to be solved badly


thanks a lot for your generous care and help

gmayor
04-17-2016, 02:47 AM
The short answer to your question is that it is not possible to do what you ask. It would have to be done in several steps as the numbers (I assume you mean those like '9300AE-10') are not formatted consistently and the variety does not lend itself to a single process.

Presumably LTR is the built-in command that applies Left to Right formatting. That being the case it is still not going to work as LTR formatting applies to the paragraph and not to the selection within the paragraph. I regret I don't know enough about right to left languages to know what the answer to this issue might be.

I don't know if this helps, but if you open the document in Word 2016, the numbers are formatted correctly. See attached

Ethen5155
04-17-2016, 03:09 AM
well then as i understood i can't create a macro that can go through all EN words and digits (individual or with a specific order) and give them LTR command??

gmayor
04-17-2016, 05:13 AM
You can certainly create a macro to do what you asked, but it will seriously screw up your document, and it won't produce the result in the PDF file I posted. Try the following on a copy of your document and you will see what I mean.


Sub Macro1()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
With oStory.Find
Do While .Execute(FindText:="[0-9]{1,}", MatchWildcards:=True)
oStory.Select
Selection.LtrPara
oStory.Collapse 0
Loop
End With
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
With oStory.Find
Do While .Execute(FindText:="[0-9]{1,}", MatchWildcards:=True)
oStory.Select
Selection.LtrPara
oStory.Collapse 0
Loop
End With
Wend
End If
Next oStory
Set oStory = Nothing
lbl_Exit:
Exit Sub
End Sub

Ethen5155
04-17-2016, 05:42 AM
Dear Graham,

I think now that I got your point and figured that you miss understood me

What I meant in your code is "selection.LtrRun" not LtrPara

Both commands are different completely, i changed your code to (Selection.LtrRun) and applied successfully on all digits



Please test my function again and please adjust your code to applied on English words and digits
Ltr run can be applied in specific selection in a paragraph

Sorry for this miss understanding and thanks for ur efforts