Hi All,
can you help me tidy up this code? Basically I am using it to bring in some data for my other code to use it, but if the dialog box opens and I press cancel it throws up a error, just because it is expecting and input.
also, I would like to clear all cells on the sheet if something is inputted (opened)
hope you can help, cheers chris
can you help me tidy up this code? Basically I am using it to bring in some data for my other code to use it, but if the dialog box opens and I press cancel it throws up a error, just because it is expecting and input.
also, I would like to clear all cells on the sheet if something is inputted (opened)
Code:
Sub OpenEnoviaUpdate()Dim wsupdate As Worksheet
Dim wsmakefrom As Worksheet
Dim strFileName As String
Set wsupdate = Sheets("Update_Drop")
wsupdate.Unprotect ("900250")
strFileName = Application.GetOpenFilename
ClearContents = wsupdate.Cells.ClearContents
With wsupdate.QueryTables.Add(Connection:= _
"TEXT;" & strFileName, Destination:=wsupdate.Cells(1, 1))
.Name = "FILEOPEN...."
.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 = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
' ClearContents
End With
End Sub
hope you can help, cheers chris