Macro Open Text to Excel Location

danenorman13

New Member
Joined
Jul 14, 2011
Messages
5
I am having trouble inserting the open file dialog box into my already created macro. Below is the dialog box string and below that is the current macro open file destination, how do insert the open dialog box into my already completed macro?

Dialog Box:
Sub XE309RR2()
Dim fname As String
Dim strTemp As String

fname = Application.GetOpenFilename("Text Files (*.txt), *.txt)")
' Test if Cancel button was clicked.
If InStr(fname, "False") = 0 Then
' Code to open the chosen file would go here.
strTemp = "You selected the '" & fname & "' file."
Else
strTemp = "You clicked Cancel!"
End If
MsgBox strTemp
End Sub

Current macro:
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\normad5\Desktop\STI 5000\Operator Dane\RUN 1\Fixture 1\XE309_N&P_LAT WITH CORR FACTORS (REV A).txt" _
, Destination:=Range("$B$2"))
.Name = "XE309_N&P_LAT WITH CORR FACTORS (REV A)_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "="
.TextFileColumnDataTypes = Array(1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top