Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim In Minneapolis - 20 Oct 2005 19:38 GMT
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 . . .
Jay Freedman - 20 Oct 2005 20:01 GMT
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).

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hi
>
[quoted text clipped - 23 lines]
>
> Gratefully . . .
Jim In Minneapolis - 20 Oct 2005 20:41 GMT
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

> Hi Jim,
>
[quoted text clipped - 41 lines]
> >
> > Gratefully . . .
Jay Freedman - 20 Oct 2005 21:22 GMT
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

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hi Jay. Thanks for helping me.
>
[quoted text clipped - 79 lines]
>>>
>>> Gratefully . . .
Jim In Minneapolis - 20 Oct 2005 22:23 GMT
Thanks, Jay!

You're fantastic.   It works wonderfully.

I am grateful for your help.

Bye

Jim

> Hi Jim,
>
[quoted text clipped - 97 lines]
> >>>
> >>> Gratefully . . .
Charles Kenyon - 20 Oct 2005 22:49 GMT
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.
Signature

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

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.

> Hi Jay. Thanks for helping me.
>
[quoted text clipped - 79 lines]
>> >
>> > Gratefully . . .
Greg - 20 Oct 2005 20:10 GMT
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
Jim In Minneapolis - 20 Oct 2005 22:24 GMT
Thanks, Greg.

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

Best Wishes

Jim

> Jim,
>
[quoted text clipped - 7 lines]
> Application.Documents.Open FileName:=oDir & oName & ".doc"
> End Sub
Jean-Guy Marcil - 20 Oct 2005 20:21 GMT
Jim In Minneapolis was telling us:
Jim In Minneapolis nous racontait que :

> Hi
>
[quoted text clipped - 23 lines]
>
> 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
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Jim In Minneapolis - 20 Oct 2005 22:25 GMT
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

> Jim In Minneapolis was telling us:
> Jim In Minneapolis nous racontait que :
[quoted text clipped - 81 lines]
> End Function
> '_______________________________________

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.