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
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