Macro not found

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having some troubles with macros and am wondering if anyone can help. I
have recorded macros and then when I go to play them it says the file cannot
be found. What I am doing when this happens is that I have been working in a
different folder and not in the folder the macro is in. When I go into the
folder the macro is in and play it, it works fine and I don't get an error
message. How do I set the macros up to look in one specific folder? I have
tried recording the macro and doing the actions (file open, go to the
specific folder, etc) but it still does not seem to work. Can anyone help me
PLEASE??? Thank you!
 
Post your macro code here and someone can probably tell you how
to fix it.
 
Macros are not contained in folders. They are contained in documents or by
default in the normal.dot template.
To change the file open directory (which is what you appear to have
recorded) you need the following command line

ChangeFileOpenDirectory "path"

where path is the full path to the directory in question.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
okay, here's the code for my one macro. I hope this helps you! Thank you!

' Macro recorded 10/13/2005 by WEichorn
' Selection.InsertFile FileName:="Letterhead.dot", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
True, DateLanguage:=wdEnglishCanadian,
CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.TypeParagraph
 
I'm no macro guru by any stretch of the imagination, but it seems
to me that if you include the foldername with the filename (e.g.,
"C:\foldername\Letterhead.dot"), it should work.
 
You are right that it does require a full path. I generally use a variable
to hold the workgroup templates path and use that as a starting point for my
path. For instance my letterhead is in the Letters and Faxes folder of the
workgroup path.

However,

(1) I think what you are doing could possibly be done bette using the
template as a template and including the date field in your template.

(2) You want your letterhead set up using headers and footers. This is
easily done in your template, not so easy using a macro.

Take a look at: How to set up letterhead or some other document where you
want one header on the first page and a different header on other pages.
http://www.addbalance.com/word/headersfooters.htm This gives step-by-step
instructions. (It also has the following links)

Some other pages to look at:

Letterhead Tips and Instructions
http://sbarnhill.mvps.org/WordFAQs/Letterhead.htm

Letterhead Textboxes and Styles tutorial
http://addbalance.com/word/download.htm#LetterheadTextboxesAndStylesTutorial

Template Basics
http://www.addbalance.com/usersguide/templates.htm

How to Create a Template - Part 2 - essential reading
http://www.mvps.org/word/FAQs/Customization/CreateATemplatePart2.htm

Word "Forms"
http://www.addbalance.com/word/wordwebresources.htm#Forms and

Word for Word Perfect Users
http://www.addbalance.com/word/wordperfect.htm if you are coming from a WP
environment (or even if you are not).

I pull updated material from my letterhead template in subsidiary
letterheads. Some of the code for this is below. It isn't perfect but it
shows how I construct the path dynamically rather than hard-coding it.

Sub AutoNew()
' First part operates only in template other than "Kenyon Legal
Letter.dot"
' Brings in Headers and styles from "Kenyon Legal Letter.dot"
' Revised 28 January 2004
'
' Designed to allow changes in main letterhead headers or styles to
' automatically propogate in forms created by using SaveAs
' from that template.
'
' The name of the Base Template ("Kenyon Legal Letter.dot") is stored
' as a document variable in that template. That variable's
' name is "BaseName." Templates created using the base template
' will also have the same variable.
'
' If the name of the base template is changed, you need to change
' the variable in not only the base template but in
' every template that is based on it or this procedure
' will generate an error.
'
Dim sTemplateName As String
sTemplateName = ActiveDocument.Variables("BaseName").Value
' If this is not the base template for the letterhead, attach base
template
If ActiveDocument.AttachedTemplate.Name <> sTemplateName Then
ReplaceHeaders (sTemplateName) ' calls private sub (below)
' Application.OrganizerCopy( ' (for future work to update letterhead
styles)
AttachBase (sTemplateName)
End If
' Second part
' All new letters - show UserForm
Dim myForm As frmAddress
Set myForm = New frmAddress
myForm.Show
Unload myForm
Set myForm = Nothing
End Sub
Function WorkGroupPath() As String
' Written by Charles Kenyon
' February 28, 2003
'
' Used by templates menus to set location of templates.
' Returns workgroup tempates path with "\" at the end.
'
' This is needed because if the folder is a network drive rather
' than a folder, it will have the "\" already. If it is a folder,
' it will not have the backslash. This function gives a string
' with the backslash in either case.
'
WorkGroupPath =
Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)
If Right(WorkGroupPath, 1) <> "\" Then
WorkGroupPath = WorkGroupPath & "\"
End If
End Function

Private Sub AttachBase(sTemplateName As String)
' Procedure written by Charles Kyle Kenyon 8 Dec 2003
' Reattaches Base Letterhead Template for form letters - attaches styles
'
Dim sTemplatesPath As String
sTemplatesPath = WorkGroupPath & "Letters & Faxes\"
'
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = sTemplatesPath & sTemplateName
.UpdateStylesOnOpen = False
.AttachedTemplate = sTemplatesPath & sTemplateName
End With
End Sub

Sub SelectIt(iField As Integer)
' Routine goes to beginning of document and then goes to field
' iField sets number of field to go to
' Used in new document menus
'
Dim iNumber As Integer
Selection.HomeKey Unit:=wdStory
For iNumber = 1 To iField
Selection.NextField.Select
Next iNumber
End Sub

Private Sub ReplaceHeaders(sTemplateName As String)
' Altered to delete stories 8 October 2005

' Replaces Header and FirstPageHeader with contents from
' base template
' Replaces Footer and FirstPageFooter with contents from
' base template
' Assumes that bookmarks have been preserved in base and copies.
' Otherwise will generate error
' Required bookmarks are "Footer1," "Footer2," "Header1," and
"Header2"
'
Dim rRange As Range
Dim sFooter As String
Dim sHeader As String
'
' First Page Header
Set rRange = ActiveDocument.StoryRanges(wdFirstPageHeaderStory)
rRange.Delete
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Header1", _
ConfirmConversions:=False, Attachment:=False, Link:=False
' Continuation Header
Set rRange = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
rRange.Delete
rRange.Style = ActiveDocument.Styles("Header 3")
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Header2", _
ConfirmConversions:=False, Attachment:=False, Link:=False
' First Page Footer
Set rRange = ActiveDocument.StoryRanges(wdFirstPageFooterStory)
rRange.Delete
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Footer1", _
ConfirmConversions:=False, Attachment:=False, Link:=False
' Continuation Footer
Set rRange = ActiveDocument.StoryRanges(wdPrimaryFooterStory)
rRange.Delete
rRange.InsertFile FileName:=WorkGroupPath _
& "Letters & Faxes\" & sTemplateName, _
Range:="Footer2", _
ConfirmConversions:=False, Attachment:=False, Link:=False
End Sub


Hope this helps,
--

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.
 
Graham, not sure what I typed but the first time I tried that it didn't work
but now it seems to! Thanks you!!!
 
Thank you! now it seems to be working great!!!!

garfield-n-odie said:
I'm no macro guru by any stretch of the imagination, but it seems
to me that if you include the foldername with the filename (e.g.,
"C:\foldername\Letterhead.dot"), it should work.
 

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

Back
Top