Results 1 to 11 of 11
  1. #1
    New Lounger
    Join Date
    Jun 2002
    Location
    Huntingdon, Cambridgeshire, England
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macros and Templates (Word 2000 SR1)

    I have a template that has two fillin-fields for name/address of recipient and for the recipient's salutation. I have an autonew macro to prompt for these with a Ctrl+End to take you to the end of the template to start the letter. I have a file that I would like to insert on occasions in a macro to just insert it. This macro is stored in the template with a keystroke shortcut. Now the problem is that, when I use the keystroke Word doesn't find the file. If I go through Tools+Macros and run it, it does. I am working on the basis that it thinks the file to be inserted is in the root directory. Is there a way out of this without either having to edit the macro? The only alternative that I can get to work, is to put the macro in normal.dot instead of the template. I don't want to use AutoText as the file can change.

    I have attached the template zipped and thanks in anticipation.

    Jackie
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Macros and Templates (Word 2000 SR1)

    According to the help for InsertFile "If you don't specify a path, Word assumes the file is in the current folder."

    What folder is the Template in?
    What folder is the file to be included in?
    What folder is the users document in?
    Why don't you specify a full path and filespec for the file to be included?

    StuartR

  3. #3
    New Lounger
    Join Date
    Jun 2002
    Location
    Huntingdon, Cambridgeshire, England
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros and Templates (Word 2000 SR1)

    Stuart,

    The template is in c:documents and settingsjackieapplication datamicrosofttemplates

    The folder that the file is to be included in is in d:

    The folder that the user's document is in is in d:

    Don't know how to unless I look at editing the macro. I'm just using the Insert+File and then inserting the required file. I don't particularly want to have to go into VB every time I want to do this type of operation.

    Jackie

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros and Templates (Word 2000 SR1)

    Hi Jackie:
    I'm not a VBA expert, but wanted to mention a something. The keystroke may not work if that keystroke has been assigned OR unassigned in the document itself. You can check whether Word thinks the keystroke is assigned by pressing Alt+Ctrl+NumPad Plus (the cursor changes to a clover) & then pressing your shortcut key. Sometimes, by assigning the same keystroke in normal.dot subsequent to creating your document, the keystroke assigned to the document will change.

    By the way, I tested your template & found that I could use your shortcut key Alt+Z to insert my document. I was able to determine that you used that shortcut by creating a document based on your template, going to Tools/Customize/Keyboard & scrolling for macros in the categories box, choosing macros, & then selecting your test macro. When you do that, it should show Alt+Z assigned.

    Hope this helps.

  5. #5
    New Lounger
    Join Date
    Jun 2002
    Location
    Huntingdon, Cambridgeshire, England
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros and Templates (Word 2000 SR1)

    Hi Phil

    I am feeling really thick here and slightly lost. Help, please.

    So when I open the template that the macro is stored in, and use your keystroke to see if Word recognises it, I get the Customise Keyboard dialog box which says that Alt+Z is assigned to my macro. Why does it work for you and not me, talk about pulling my hair out! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    When I then try using Alt+Z, I then get the dialog box that gives me "Run time error 5174, file not found". Where were your template and file to be inserted located?

    Thanks. Jackie

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros and Templates (Word 2000 SR1)

    <P ID="edit" class=small>(Edited by Phil Rabichow on 03-Feb-03 00:14. Edited to add the last paragraph)</P>Actually, all I did was download your zip file to a download folder, open winzip & then I both created a new file from your template & opened your template. Either way, the shortcut key worked. Are you trying this on an existing document? If so, you might have Alt+Z assigned to something else.

    If you open a document based on normal.dot, is Alt+Z assigned to anything? What if you rename normal.dot & let Word create a new one...is Alt+Z assigned to anything? Do you have other templates in your startup folder (i.e. add-ins)?

    Why don't you try assigning a new shortcut key to the macro, just to see what happens? If you can't find the problem, try zipping the file in which the shortcut key doesn't work.

    I found the following on a Google search. If it doesn't make sense to you, maybe one of the VBA experts could explain it. I'm copying it, but have no idea what it does, other than it solved the error message for another person. Modify the following for your macro:
    <pre>Dim p As String
    Dim f As String

    p = "c:test"
    f = Dir(p & "*.doc")

    Do While f <> ""
    Documents.Open p & f
    'Your test line:
    Selection.TypeText Text:="This is a test"
    ActiveDocument.Close SaveChanges:=True
    f = Dir
    Loop</pre>


  7. #7
    New Lounger
    Join Date
    Jun 2002
    Location
    Huntingdon, Cambridgeshire, England
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros and Templates (Word 2000 SR1)

    Hi Phil, I managed to get it to work once with a brand new template, and then it hasn't worked since.

    I have deleted normal.dot, so starting with a clean sheet, but it still won't work. I must be doing something wrong if you are able to get it to work. When you say that the shortcut key worked - what was displayed on the screen when you used it?

    There are no templates or add-ins in the startup folder. I don't want to go into the VBA screen, as this will also be (I think) used for training purposes.

    Jackie

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros and Templates (Word 2000 SR1)

    Hi Jackie:
    If I open the document & use Tools/Customize/keyboard, I see the attachment. If I open the template, I can press Ctrl+Shift+NumPad Plus & I see the shortcut key.
    Attached Images Attached Images

  9. #9
    New Lounger
    Join Date
    Jun 2002
    Location
    Huntingdon, Cambridgeshire, England
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros and Templates (Word 2000 SR1)

    Hi Phil, the shortcut key works, but the macro doesn't. I get the runtime error message telling me that the file I am trying to insert hasn't been found which is what the macro is about. Does this make sense? So, yes, I do the Alt+Z to run the macro which works, but then I get the message telling me that it can't find the file - this is the issue. It is looking for the file in the root directory, and I don't know how to get round this problem without having to go into the coding and I can't believe that I have to for something so simple.

    Jackie <img src=/S/flags/UK.gif border=0 alt=UK width=30 height=18>

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macros and Templates (Word 2000 SR1)

    <P ID="edit" class=small>(Edited by jscher2000 on 03-Feb-03 14:44. Duh... you told us!)</P>Your code tells Word to insert "Doc.doc" but doesn't mention where to find it. Assuming this file exists, Word probably is checking the "last used File Open path." You usually can determine where Word is looking by interrogating this property in the Immediate window:

    ?options.DefaultFilePath(wdCurrentFolderPath)

    To have complete control, you have to specify the full path in the FileName parameter. You don't need to do this more than once, just change it to:

    FileName:="doc.doc"

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macros and Templates (Word 2000 SR1)

    Oh wait, the file can change! Do you want to pop up the InsertFile dialog for the user and let her/him pick the file?

    <pre>Sub InsertFileFromD()
    'Display InsertFile dialog open to d: folder
    With Dialogs(wdDialogInsertFile)
    ChangeFileOpenDirectory "d:"
    If .Display = -1 Then
    'you can muck with dialog settings before inserting
    .Execute
    'you can muck with the document after inserting
    Else
    'user canceled, do nothing
    End If
    End With
    End Sub</pre>

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •