User Prompted Macro?
Results 1 to 2 of 2

Thread: User Prompted Macro?
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question User Prompted Macro?

    Hello I am new to excel and VBA coding and have not been able to figure out how to complete what I would like to do. I have been able to make simple macros but this is more in depth I believe. The goal: Create a macro that when the excel file is opened the user will be brought to a specific file that Csv. files will be saved with data. The user will then choose the desired file that will be imported into the excel file that they opened in order continue with the information. I appreciate your time and any info you can provide for me! Thank you

  2. #2
    Board Regular
    Join Date
    Dec 2013
    Posts
    214
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: User Prompted Macro?

    Hi,
    This is a quick solution that I have cobbled together, when the document is opened it will open the location of your choice and only show CSV fie formats.
    if the person cancels the file choosing it will not care and just sit as a blank XLSM file.

    You may want to also do something about when the user saves as I am guess you will not want this XLSM format....but that's something else to think about in the future


    Code:
    Private Sub Workbook_Open()
    On Error Resume Next
    Dim ws As Worksheet, strFile As String
    With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialFileName = "C:\" 'set you default file location here
    Set ws = ActiveWorkbook.Sheets("Sheet1") 'set to current worksheet name if required
    strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please select text file...")
    End With
    With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
         .TextFileParseType = xlDelimited
         .TextFileCommaDelimiter = True
         .Refresh
    End With
    End Sub

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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