Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2023, 03:55 AM
maw444 maw444 is offline How to refer to a file in the same directory Windows 10 How to refer to a file in the same directory Office 2019
Advanced Beginner
How to refer to a file in the same directory
 
Join Date: Feb 2021
Posts: 40
maw444 is on a distinguished road
Default How to refer to a file in the same directory

I have a document where a user opens the document and it runs a macro.



I want to have a tick box so that if a user clicks 'yes' it adds the text from a Word file which is stored in the same directory as the 'macro' base file is stored.

How do I refer to this? I know to use the file name but does Word / VBA assume it will be in the same directory? If not how do I tell it?
Reply With Quote
  #2  
Old 06-07-2023, 04:42 PM
Guessed's Avatar
Guessed Guessed is offline How to refer to a file in the same directory Windows 10 How to refer to a file in the same directory Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You will need to be explicit in providing the actual path. In VBA you could use
Code:
ThisDocument.Path & Application.PathSeparator & "My Doc.docx"  'or
ActiveDocument.Path & Application.PathSeparator & "My Doc.docx"
ThisDocument is the file where the macro is sitting
ActiveDocument is the document which is currently active (on top)
Application.PathSeparator is a tortuous way to write \ but we use it in case the code is being used on a Mac, in which case it becomes ":" because that is how a Mac separates folders
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strip out numbers from file names in a directory. JustJim Word VBA 2 10-20-2021 06:40 PM
How to refer to a file in the same directory Using Word VBA to change file names in a directory sg11 Word VBA 4 03-22-2018 04:25 AM
How to refer to a file in the same directory Changing file directory from a temp folder dwirony Word VBA 6 12-13-2016 09:41 PM
How to refer to a file in the same directory Replacing jpg file in each file of a directory hklein Word VBA 4 10-14-2013 04:40 PM
Auto-File Naming/ Default Directory Saves sgill32 Word 2 11-06-2008 02:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft