Hi
I am new to using Excel and vba and would very much appreciate any help on my issue. I am importing two .txt files into my excel workbook in two sheets with a macro. Once imported i will edit the data with a macro. When i run the macro it open a window to select the file but when i click ok i am getting an error and i think its with this line of code
With ActiveSheet.QueryTables.Add(Connection:=selectFile, _
Destination:=Range("$A$1"))
Dim selectFile As String
selectFile = Application.GetOpenFilename(FileFilter:="Text files, *.txt")
If sFile = "False" Then Exit Sub
Sheets("OPA Forecast").Select
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:=selectFile, _
Destination:=Range("$A$1"))
.Name = "OPA_Fertility_Forecast_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Thanks in advance with any expertise you may be able to provide.
I am new to using Excel and vba and would very much appreciate any help on my issue. I am importing two .txt files into my excel workbook in two sheets with a macro. Once imported i will edit the data with a macro. When i run the macro it open a window to select the file but when i click ok i am getting an error and i think its with this line of code
With ActiveSheet.QueryTables.Add(Connection:=selectFile, _
Destination:=Range("$A$1"))
Dim selectFile As String
selectFile = Application.GetOpenFilename(FileFilter:="Text files, *.txt")
If sFile = "False" Then Exit Sub
Sheets("OPA Forecast").Select
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:=selectFile, _
Destination:=Range("$A$1"))
.Name = "OPA_Fertility_Forecast_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Thanks in advance with any expertise you may be able to provide.