User Prompted Macro?

evmike123

New Member
Joined
Jun 13, 2019
Messages
1
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
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

bugmonsta

Board Regular
Joined
Dec 17, 2013
Messages
214
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,733
Messages
5,488,551
Members
407,646
Latest member
utl1095

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top