Silly "enter-value" macro question! (Does anybody know?)

J

Jim In Minneapolis

Hi

Does anyone know how to make this macro? You'll be a 'life-saver' for me if
you do!

(NOTE: I do not have any experience using the macro "editor" -- I've only
used the 'record macro' function so far. So if you want me to enter some
code, would you please just write it in a way I can "cut-n-paste" into the
editor?)

STEPS:
(a) Click on toolbar macro icon
(b) This should bring up an "enter value" dialog box on the screen
(c) I will then type-in: 1 (i.e. I just type the number one)
(d) I click "ok" (or whatever the dialog box wants)
(e) Then Word opens this specific document on my hard drive: c:\MS
Word Docs\1.doc

(I have about 30 documents . . . so, depending on what # is entered in the
dialog box, the corresponding document will open . . . i.e. 1.doc, 2.doc,
3.doc . . .)

Thanks so much! I know this is probably pretty simple for you macro pros,
but I don't know how to do it.

Gratefully . . .
 
J

Jay Freedman

Hi Jim,

Taking your request literally, this macro will do what you asked:

Sub OpenNumberedDoc()
Dim TheNumber As String

On Error Resume Next
TheNumber = InputBox$("Enter the doc number")
If TheNumber <> "" Then
Documents.Open FileName:= _
"c:\MS Word Docs\" & TheNumber & ".doc"
End If
End Sub

Thinking a bit sideways, though, you might be better off using the Work menu
(http://word.mvps.org/FAQs/General/WorkMenu.htm).
 
G

Greg

Jim,

Just assign something like the following to a toolbar icon:

Sub JimFileOpen()
Dim oDir As String
Dim oName As String
oDir = "C:\MS Word Docs\"
oName = InputBox("Type the file number:", "Enter Value")
Application.Documents.Open FileName:=oDir & oName & ".doc"
End Sub
 
J

Jean-Guy Marcil

Jim In Minneapolis was telling us:
Jim In Minneapolis nous racontait que :
Hi

Does anyone know how to make this macro? You'll be a 'life-saver'
for me if you do!

(NOTE: I do not have any experience using the macro "editor" -- I've
only used the 'record macro' function so far. So if you want me to
enter some code, would you please just write it in a way I can
"cut-n-paste" into the editor?)

STEPS:
(a) Click on toolbar macro icon
(b) This should bring up an "enter value" dialog box on the screen
(c) I will then type-in: 1 (i.e. I just type the number one)
(d) I click "ok" (or whatever the dialog box wants)
(e) Then Word opens this specific document on my hard drive:
c:\MS Word Docs\1.doc

(I have about 30 documents . . . so, depending on what # is entered
in the dialog box, the corresponding document will open . . . i.e.
1.doc, 2.doc,
3.doc . . .)

Thanks so much! I know this is probably pretty simple for you macro
pros, but I don't know how to do it.

Gratefully . . .

Here is some code with basic error trapping to make sure there are no
"silly" errors...


Just change the path (Documents.Open... line) if necessary and the upper
limit number (Const UpperLim As... line) in the code.

'_______________________________________
Const UpperLim As Long = 30
'_______________________________________
Sub myOpenFile()

Dim MyFile As String

MyFile = ""

Do
If MyFile <> "" Then
'If we get in this If block,
'This is a second pass because user did not type a valid number
MsgBox "You must type a valid number (From 1 to " _
& CStr(UpperLim) & ").", vbExclamation, "Try again"
End If
MyFile = GetNumber
If MyFile = "" Then Exit Sub
Loop While CLng(MyFile) > UpperLim Or MyFile = 0

Documents.Open "C:\MS Word Docs\" & MyFile & ".doc"

End Sub
'_______________________________________

'_______________________________________
Function GetNumber() As String

GetNumber = ""

Do
If GetNumber <> "" Then
'If we get in this If block,
'This is a second pass because user did not type a number
MsgBox "You must type a number.", vbExclamation, "Try again"
End If
GetNumber = InputBox("What file number do you want to open?", "Open
File")
If GetNumber = "" Then
'User cancelled out of Inputbox or did not type anything
MsgBox "You have not chosen a file number.", vbExclamation,
"Cancelling"
Exit Function
End If
Loop While Not IsNumeric(GetNumber)

End Function
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jim In Minneapolis

Hi Jay. Thanks for helping me.

Ok. I looked at the "Work Menu" FAQ. But I think it says you can only use
10 documents . . when adding the 11th it 'bumps' the old #1 doc off the list!
So, since I already have 30 docs . . and probably more to go . . . that
won't work.

Regarding the macro you kindly wrote for me, when I use it here's what
happens:
(a) The 'dialogue' box pops up (very nice!). It says "enter doc"
(b) I type in 1 (just the number 1) and click
(c) The dialogue box disappears, but then NOTHING happens. (I'm left just
looking at a blank empty page).

Woud you mind looking at the exact code below? I have edited your macro
just to indicate the correct full path for my actual document folder. That's
all I changed. Note there IS a ^ symbol in the file path--just so it doesnt
'look like a typo!

Here it is:

Sub OpenNumberedDoc()
Dim TheNumber As String

On Error Resume Next
TheNumber = InputBox$("Enter the doc number")
If TheNumber <> "" Then
Documents.Open FileName:= _
"C:\MS Word Documents\Cheap Resumes and Typing While-You-Wait\^Job
Descriptions" & TheNumber & ".doc"
End If
End Sub
 
J

Jay Freedman

Hi Jim,

Yeah, I forgot about the limit on the Work menu. Nice idea while it lasted.
<g>

Your change missed the backslash that has to go between the word
Descriptions and the quote mark. Word was trying to open a file named
^JobDescriptions1.doc and failing with a "file not found" error, but the On
Error trap caught the problem and simply ended the macro without a big nasty
error message.

If you want something a little more informative when the macro runs into
trouble, add these lines just after the End If line:

If Err.Number <> 0 Then
MsgBox Err.Description
End If
 
J

Jim In Minneapolis

Thanks, Jay!

You're fantastic. It works wonderfully.

I am grateful for your help.

Bye

Jim
 
J

Jim In Minneapolis

Thanks, Greg.

I appreciate your help. You guys on this forum really rock!

Best Wishes

Jim
 
J

Jim In Minneapolis

Thanks so much Jean-Guy

I wish I knew French . . . so I could say something in your own language!
heh-heh

Your suggestion is much appreciated. Ok, I've got all the answers I need
now . . . thanks to Jay and all you guys.

Have a great weekend!

Jim
 
C

Charles Kenyon

Jumping into the middle of this, take a look at
http://addbalance.com/word/templatesmenu.htm. It gives directions for
building a menu to create new documents from templates. You could, instead,
record macros opening your documents and put those on a custom menu.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top