View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
jimjk jimjk is offline
external usenet poster
 
Posts: 4
Default Macro recently quit working

Thank you for replying!
Since I am new at posting I am not certain if I should reply in General or
individually but here goes.
When I put breakpoint at the if statement and continued hitting F8 it worked
fine
it also completed normally if I hit F5 but failed without the breakpoint.
When I added this beep code
For I = 1 To 30 ' Loop 3 times.
Beep ' Sound a tone.
Next I
right after 2nd End if I heard Beep in auto mode prior to completion of
getfilename gui.
the complete subroutine is:

Public HeadLine As String
Public ThisLine As String
Public Checkfilenum
Public TotalRows
Public NDresults

Sub CombineMultFiles()
' CombMultFiles() loads selected text files from disk and calls
' Comb_1 to add the Data (2) worksheet from each file individually
'
'
'
Application.ScreenUpdating = False

'Global initialization
HeadLine = "FirstOne"
Checkfilenum = 0
' Check to see if values were set by add data routine
' and the program called from there

If IsEmpty(TotalRows) Then ' <<<<breakpoint for f5 continue of f8 step
TotalRows = 0
NDresults = 1
End If
' Standard routine for requesting file names
Dim fn As Variant, f As Integer
fn = Application.GetOpenFilename("Text Files (*.txt),*.txt", 1, "Select One
Or More Stat files To Combine/process", , True)
If TypeName(fn) = "Boolean" Then Exit SubIf TypeName(fn) = "Boolean" Then
Exit Sub
End if
'<<<<beep code was tried here
For f = 1 To UBound(fn)

Workbooks.OpenText Filename:=fn(f) _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:= _
False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1)
' ********** file did open ***********

ThisLine = Range("A6").Value ' added breakpoint here but it never got here.
Application.DisplayAlerts = False
Call Comb_1
Next f
Workbooks("dresults.xls").Activate
newfilename = "combinedfiles" + Str(NDresults) + ".xls"
ActiveWorkbook.SaveAs Filename:=newfilename, FileFormat:=xlNormal
Application.ScreenUpdating = True
If Checkfilenum 0 Then
errmes = "There was a total of " + Str(Checkfilenum) + " files that
failed."
MsgBox (errmes)
End If
If NDresults 1 Then
errmes = "There was a total of " + Str(NDresults) + " combinedfiles
created from this data."
MsgBox (errmes)
End If
For I = 1 To 30 ' Loop 3 times.
Beep ' Sound a tone.
Next I

End Sub

"Tim Williams" wrote:

In what way is it failing: does it raise an error or just not do what you
expect it to ?

You should post a more complete set of code: it's not possible from your
description to say what the problem might be.

Tim

"jimjk" wrote in message
...
I have a macro which Has been in use for several months. Recently it failed
so I started up the editor and step through the program manually. it
worked
like it always did. Tried running in auto the same problem occured. I then
added a breakpoint. It stopped at breakpoint and I hit F5 again it
completed
without a hitch. I added some do loops with a Beep and I am hearing the
Beeps
before some previous steps are finished. The command before the loop is
"fn =
Application.GetOpenFilename("Text Files (*.txt),*.txt", 1, "Select One Or
More Stat files To Combine/process", , True)"