+ Reply to Thread
Results 1 to 11 of 11

Importing a text document via macro button

  1. #1
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Question Importing a text document via macro button

    Hello Everyone,

    Thanks for help up front.

    I have the programming done that allows me to click the macro button and select a text file to import. It all works wonderfully. However, I want to ask a question about programming the directory that opens in the dialogue box when you click the button.

    This template will potentially be used by other people, so when I point the command to C:\Users\"Clarkit's"\Documents (the user of the computer, and documents, location the text file will always be in), will excel automatically use the current user of the template, or will it come up with and error and say "file directory doesnt exist"?

    My question is, is there a way to define the "current user", or the account that the template is being used under?

    So instead of this:
    ChDir "C:\Users\Clarkit\Documents"
    fName = Application.GetOpenFilename()

    Excel will automatically fill in the blank with the correct user?
    ChDir "C:\Users\ _______\Documents"
    fName = Application.GetOpenFilename()


    This is a tricky one!

    Thanks!
    Last edited by Clarkit; 01-03-2014 at 01:23 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Importing a text document via macro button


    Hi,

    very easy level !

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Importing a text document via macro button

    Thanks for the reply, and from Paris! Cool. Greetings from the States

    Do I just input your code like this?
    Please Login or Register  to view this content.
    Last edited by Clarkit; 01-03-2014 at 01:23 PM.

  4. #4
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Importing a text document via macro button

    Thanks for the reply, and from Paris! Cool. Greetings from the States

    I think this code only tells me what the current users path to the documents folder is. I want the Application.GetOpenFilename() command to go directly to the correct path without any navigation.

    Thanks!

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Importing a text document via macro button

    i think theres an easier way, but cant remember at the moment

    Please Login or Register  to view this content.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  6. #6
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Importing a text document via macro button

    try this one

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Like this :

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Importing a text document via macro button

    Sorry, i didnt read the question properly
    you can use the following to get various folder paths

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Like this :

    Hello Marc,

    That did the trick! Thank you!

  10. #10
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Importing a text document via macro button

    Thanks for the input Sean!

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Beware in case of relocation of Documents folder …

    Please Login or Register  to view this content.

    My easy way works only in standard user session
    but in case of relocation of user folders the better is to follow Sean's code :
    Please Login or Register  to view this content.

    Any chance to see my reputation growing …

  12. #12
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Beware in case of relocation of Documents folder …

    Quote Originally Posted by Marc L View Post

    Any chance to see my reputation growing …
    I grew it twice

    I changed your suggestion to :

    Please Login or Register  to view this content.
    Thanks guys!
    Last edited by Clarkit; 01-03-2014 at 02:15 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. importing info from text file with multiple heading through document to excel
    By neale scott in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-13-2013, 08:30 PM
  2. Macro: Importing data from another xls document
    By heyviggy in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-04-2012, 07:17 AM
  3. Macro to copy from a text document into excel document
    By JRoder in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-25-2012, 07:31 PM
  4. Help with a Macro to copy from a text document into excel document
    By JRoder in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2012, 07:41 PM
  5. Macro with button to Convert into PDF Document
    By DoubLeA in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2012, 06:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1