G
Guest
I am looking for help on this macro I wrote to get a filename, open a file,
grab some cells, then close the file. What I need help with is having the
macro skip a section (go to line 10) if the file is not found to open. Right
now it will close my workbook I'm dumping info into. Also, any idea why my
variable Caccel would be truncated when it should have 3 decimal places?
Thanks in advance!
For i = 1 To NumMatrices
On Error Resume Next
Fname = "C:\Documents and Settings\My Documents\" & Tname & ".txt"
ChDir _
"C:\Documents and Settings\My Documents\"
Workbooks.OpenText Filename:=Fname, Origin:=437, StartRow:=1,
DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False,
Semicolon:=False, _
Comma:=False, Space:=True, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)),
TrailingMinusNumbers:=True
Cells.Find(What:="release", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Dspeed = ActiveCell.Offset(0, 2).Value
Cells.Find(What:="accel", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Caccel = ActiveCell.Offset(0, 1).Value
ActiveWorkbook.Close
' Workbook = wb1
If Cells(Row, 11) = "" Then
Cells(Row, 11) = Dspeed
Else
End If
If Cells(Row, 12) = "" Then
Cells(Row, 12) = Caccel
Else
End If
If Cells(Row, 12) = 0 Then
Cells(Row, 11) = 0
End If
10 Row = Row + 1
Cells(Row, 2).Select
Tname = Selection
Next
grab some cells, then close the file. What I need help with is having the
macro skip a section (go to line 10) if the file is not found to open. Right
now it will close my workbook I'm dumping info into. Also, any idea why my
variable Caccel would be truncated when it should have 3 decimal places?
Thanks in advance!
For i = 1 To NumMatrices
On Error Resume Next
Fname = "C:\Documents and Settings\My Documents\" & Tname & ".txt"
ChDir _
"C:\Documents and Settings\My Documents\"
Workbooks.OpenText Filename:=Fname, Origin:=437, StartRow:=1,
DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False,
Semicolon:=False, _
Comma:=False, Space:=True, Other:=False,
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)),
TrailingMinusNumbers:=True
Cells.Find(What:="release", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Dspeed = ActiveCell.Offset(0, 2).Value
Cells.Find(What:="accel", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Caccel = ActiveCell.Offset(0, 1).Value
ActiveWorkbook.Close
' Workbook = wb1
If Cells(Row, 11) = "" Then
Cells(Row, 11) = Dspeed
Else
End If
If Cells(Row, 12) = "" Then
Cells(Row, 12) = Caccel
Else
End If
If Cells(Row, 12) = 0 Then
Cells(Row, 11) = 0
End If
10 Row = Row + 1
Cells(Row, 2).Select
Tname = Selection
Next