Results 1 to 3 of 3

Thread: Open file in same directory as open macro-enabled file (on USB drive)

  1. #1
    Junior Member
    Join Date
    Mar 12
    Posts
    31

    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

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,526

    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

  3. #3
    Junior Member
    Join Date
    Mar 12
    Posts
    31

    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
  •