Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a Reference Directory to Insert Files From - Word 2003 VBA v6

Status
Not open for further replies.

nzimmerm

Technical User
Nov 12, 2009
3
CA
Hello,

I'm working on some macros in Visual Basic v6.5 and I need some help! I currently have some macros that insert files into a generic template document to make it customer specific. However, these macros use a hard-coded location on our server to locate the files and I want to change this.

What I want is for the macro to detect the location of the open word document (generic template) and set this as the default directory so other files that get inserted via macros (located in the same folder as the open word document) can be inserted without having to provide a hard-coded location. The reason we want to do this is because the folder which contains all these files may be moved around or moved to a new server and we want to avoid the hassle of re-programming every time a move is made.

Is there any hope for me?

Thanks so much,

Naomi
 



Hi,

Please post the relevent code that you are currently using, that need to be modified.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
This is how I'm currently inserting files...

Selection.InsertFile FileName:="\\H22C1R1-ENVIR01\Public\13.0 R&D\Design Review Documentation\O&M Manual - Naomi\Zinc Handling.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

As you can see, the file location is hard-coded to a specific spot in our server. Ideally I want something that would

1) Detect the location of the template file and set that location as the directory from which to open files
2) Be able to insert the specific files using simply the name of the document to be inserted, i.e. "Zinc Handling.doc"

Does this help? I'm a newbie to VBA coding so I apologize if I can't provide an adequate description.

Thanks so much,

Naomi
 


I think this might work. It is not the ThisDocument object as that's the one that your code is running in.
Code:
Selection.InsertFile FileName:=[b]Selection.Parent.Path & "[/b]\Zinc Handling.doc", Range:="", _
        ConfirmConversions:=False, Link:=False, Attachment:=False

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Have a look at the Path property of the ActiveDocument or ThisDocument object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 




ActiveDocment.Path might be better, since you have Selected in it, it is active.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks PHV, using the ActiveDocument Path property solved my problems!! Hooray.

Skip, Thank you for your help also!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top