Hey guys, Daniel here again with another tectorial for you. This time on a question that I received
from one of my viewers about doing a Macro with some extra code in there. So let's have a look at
this. Thanks to Mary page for your question and suggestion on the video. You asked if I can make
a video to show how to create a macro using F2 as the hot key and the Macro to advance to the
next asterisk symbol. Hopefully I'm understanding this correctly. So I have templates that I fill in
certain spaces wrote the templates which have an asterisk symbol where the next entry needs to be
made. So I want to be able to open my template and use the F2 key to advance your cursor to the next
Astrisk symbol in the document. I'm stuck on how to get the recording of the advancement of the
cursor to the asterisk. So thanks for your question. Now that I'm reading this after beginning to
record this, I'm thinking maybe you're asking just to see that the F2 key will only advance the
next Astrisk symbol or to do some other command and then do that. I think it's better to have
it all in one command. So if you're going to be doing the same thing in each one. But I can show
you both in here. It's a two-step process where you're going in to record a Macro and then the
second part is to edit the Macro. So I'm going to show you exactly how to do this. Coming right up.
Alright, so let's have a look at my screen here and I'll show you how to do this. So I did up a
mock document just to kind of show what I think that Pam might be looking at. So what we want to
do is in the beginning of this document, we're gonna go, so I went under view, because we're at
the home screen. We're already under view, macros, and record a macro. So I believe you already know
how to initiate doing a macro. So we're going to do, I'll call this F2 next. So it's gonna be using
the F2 key to run to the next Astrisk symbol. So it's going to be a keyboard command and I will press F2
to assign it to the F2 key and save changes in, I want to do it only for this document. I don't
want to do it for the global template. So we'll hit assign and close and now it's recording. So at this
point we don't need to add anything if you just want to add the asterisk symbol or to find the
next Astro symbol. We can just stop the recording now, but if you want to add something else first.
alright. So I put in some text there maybe you want to bold it or just part of it.
Then we'll stop recording. So we've got the first part of our macro done. So when we hit
F2 all it's gonna do at this point. I'll just do a new line here and hit F2 it puts in the
string of course it's carrying from where it left off that is not what I want it to do. So I'm gonna
just make this a little bit more realistic. Alright, to, there. So it's not keeping my underline
on here for some reason. So I didn't record that part but that's not what this tutorial is about.
So we're gonna move forward and under view, macros, view macros. Now I don't see my macro in here. I'll
search global. So I got the macro. I want to edit now we can see the part of the macro
where it typed in the text that we have and then it was doing some bolding, italic, underline, and
it's screwed up in here somewhere. So but rather than deal with with that or redoing it that's kind of
irrelevant to what we're doing. So what we want now is to add. I'm just gonna make this smaller here.
So we're gonna add the other code. So where we add the code will make a difference. If we
want to do it at the beginning of the code. So it will search for the asterisk first and then run
the script typing in the text. Bold and italic all that stuff or do we run the adding of the
text first and then search for the next Asterisk symbol, in which case you would add it after the
end if. So we can try both. So on a quick Google search I was able to get the command for that.
So its selection.find.execute and then we have a space in there and then it's
findtext :="*" so it it's gonna put in that asterisk symbol or I'm sorry
it's gonna find that asterisk symbol, then it will type in this text. So if we close out of this edit.
delete what I had there. So now if I hit F2 it jumped down here. It found
the Asterisk symbol and it inserted that. So the next one would jump down below
line five and then line eight so I'll just hit F2 right from here and
it did that one correctly and then I'll hit it again and it did that perfectly.
So it's searching for the next symbol and then it's doing that. So I'm going to undo
Alright, so let's go back and view the macro edit. So here's the command that we added and
I'll put that in the comments below for you so you can just copy and paste that.
But I'm gonna cut that out of there and I think now I'll have to test that. We'll
put it right here just below the end sub. Because this is part of this sub here. So,
now it's gonna type in, when I hit F2, it should put in the text right here where
my cursor is now above line one and then go down to the Asterisk symbol. So let's try it.
and it did. It inserted that line right there and now it found and highlighted the
next Asterisk symbol. So if I hit F2 again it should replace that symbol with the
text under line three and then jump to the one under line five and it did perfectly.
So obviously this is working great. So it depends if you want it to find the symbol first and
then insert it or insert the text and then find the symbol. If you didn't want it to do anything
except just find the text and we go in here and edit this and we can delete all of this
so really this whole subroutine is just finding the symbol. So that's back out of all this.
So if I hit up to it found the first Asterisk symbol. It hasn't typed anything yet. So if I hit F2 again
it found that one under five and again the one under eight. So this is working perfectly now as
well by simply finding the symbol and it's not doing anything. It's available for you too now
there you go. Hopefully that is what you were looking for. I gave you a few variations of
what you can do. Searching before or after as well as just searching and not doing anything
but search for the next symbol and that ties it into the F2 key on the keyboard. You can do
that with any key that you want. That's it for this tutorial. Please give it a thumbs up, share,
subscribe if you haven't already and stay tuned for more videos. Alright, thanks guys. Bye for now.