Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

record macro with input boxes 1

Status
Not open for further replies.

ad602000

IS-IT--Management
Jul 10, 2002
17
AU
Hi,
I am a total green as grass newbie to macros etc. What I would like word to do is, I have bookmarks on a template to which I want to be able to input text name address etc. I was thinking of doing fillin fields but rather than manually navigating through, I wanted to record a macro where the navigation would be handled by the macro.

My question is, how do I ensure that the macro will allow input and not move on to the next fillin field until the "ok" button is clicked? Do I have to change the code in someway or do something while recording the macro?

Many thanks in advance
Peter
 
There are various ways of doing it. Here is one of them:

You say you have got bookmarks. I will name the first one Book1 for this example.

- Record a macro, where you jump from bookmark to bookmark using the goto function. You get a lot of code, of which the first line is interesting:

Code:
Selection.GoTo What:=wdGoToBookmark, Name:="book1"

- You then copy this into a nice clean sub:

Code:
sub Text_input()
    ' Here you define a variable to save the information from the inputbox:
    Dim FirstBitOfText As String

    ' Now you fill the variable with text, using vba's InputBox function:
    FirstBitOfText = InputBox("Put your text in here", "Title of InputBox")

    ' Then you hop to the bookmark, which you called book1
    Selection.GoTo What:=wdGoToBookmark, Name:="book1"

    ' And you insert the contents of the variable after the bookmark:
    Selection.InsertAfter FirstBitOfText

    ' You don't collapse, but remove the highlighting of what you have just inserted:
    Selection.Collapse

end sub

- Repeat this within the same subprocedure (putting all the DIMs at the top, to be sure they are there) as many times as you have bookmarks and don't forget to save every few minutes. When you are finished and are happy with it, create a new button in one of the control bars at the top of the document. Attach the macro to it. That way, people click onto the button and the whole thing runs through.

- So you don't get any nasty surprises, when you are starting to record the macro, save it into normal.dot, so it is always there when you use Word. If you are creating a template then you can save it there if it is only relevant to that template.

- Good luck :)

Once it works nicely, you will find out that people manage to make a lot of mistakes, like clicking onto OKOKOKOKOK all the way through and then wondering why no text appeared. That is another chapter.

Carol, Berlin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top