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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

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,099,248
Messages
5,467,517
Members
406,544
Latest member
semoredhawk

This Week's Hot Topics

Top