defining a dynamic path in VBA

gayjaybird

New Member
Joined
Aug 6, 2007
Messages
39
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:

Code:
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?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top