# defining a dynamic path in VBA



## gayjaybird (Mar 27, 2009)

I'm using Microsoft Word 2007.  I am trying to write a macro to format selected text and place an icon to the left of it in documentation.  Here's the code I've managed to come up with:


```
Sub OnePointTip()
'
' OnePointTip Macro
'
'
    Selection.Font.Name = "Times New Roman"
    Selection.Font.Size = 12
    Selection.Cut
    Selection.InlineShapes.AddPicture FileName:= _
        "C:\Users\gayjaybird\Desktop\projectTemplates\tip.gif", LinkToFile:=False, _
         SaveWithDocument:=True
    Selection.Cells.Split NumRows:=1, NumColumns:=2, MergeBeforeSplit:=False
             Selection.Cells(1).Next.Select
             Selection.PasteAndFormat (wdPasteDefault)
End Sub
```

There are 3 different sets of formatting that they want, but the logic works the same in each.  I generated this code by recording the macro and performing the functions I needed.  How do I code the file path of the icon so that I can share this with other users?  A network path is not desirable because there may be multiple users accessing the image at the same time.  The only way I could see is to create a folder on each user's PC and then edit the coding so it reflects the proper file path.  Is there a way to dynamically do this so I don't have to keep re-editing the macro?


----------



## Macropod (Mar 27, 2009)

Hi gayjaybird,

One way of dealing with this would be to put the images in the users' Workgroup Templates folder (see under Word Options|Advanced > File Locations > Workgroup Templates), which could be defined if this hasn't already been done. That way, each workgroup could have a single location where both their templates and template images could be stored.

Then, in your code, you could specify FileName:= as:
FileName:= Options.DefaultFilePath(wdWorkgroupTemplatesPath) & "\tip.gif"

Cheers


----------

