|
-
Aug 10th, 2012, 04:47 AM
#1
Thread Starter
Junior Member
Open file in same directory as open macro-enabled file (on USB drive)
Hi guys,
I'm using the following code to bring text from a file into a cell in a word table.
This works great when the files are on a desktop and I can specify the path but I now need to use this file on the move and so the pah will always change.
The file being opened is always in the same directory as the macro-enabled file so what would I need to change to get this to work?
Code:
Code:
f = FreeFile
Open "C:\localdata\Passdown\log1361.txt" For Input As f
strvar = Input(LOF(f), #f) ' read file into variable
Close f
Thanks
-
Aug 10th, 2012, 04:51 AM
#2
Re: Open file in same directory as open macro-enabled file (on USB drive)
Code:
Open activedocument.path & "\log1361.txt" For Input As f
or thisdocument.path
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 10th, 2012, 05:00 AM
#3
Thread Starter
Junior Member
Re: Open file in same directory as open macro-enabled file (on USB drive)
Thanks once again westconn1...in my defence I had tried ThisDocument.path "\logxxx.txt" and when that didn't work i was stumped!
Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|