Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Weird VBA problem

The code below works.

It is just a simple loop that lists files in my "C:\Less\In\"
directory.

Notice that the "Calculate" keyword is memo only.
Now if I activate calculate by removing the "'" I get a "Run-time
error 5 " message on the first run of the Sub. On subsequent runs it
is ok ?!
(The "str_FileName = Dir " line is highlighted on Debug)

If I adjust its position on the line (not within the code itself) I
get the message on the first Sub run again!

How can this be?





Sub L()

Dim str_FileName As String 'Name of file in AllJnls folder.
Dim str_MyPath As String 'Path to the AllJnls folder.

' Loop to get all LESS IN Files.
str_MyPath = "C:\Less\In\" ' Set the path.
str_FileName = Dir(str_MyPath) ' Retrieve the first
entry.

Do While str_FileName < "" 'Loop for each file.

'Calculate

Debug.Print str_FileName

str_FileName = Dir ' Get next file.

Loop
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Weird VBA problem

you need to specify which object the calculate method is to work on be that
the application, or a range.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bob" wrote in message
om...
The code below works.

It is just a simple loop that lists files in my "C:\Less\In\"
directory.

Notice that the "Calculate" keyword is memo only.
Now if I activate calculate by removing the "'" I get a "Run-time
error 5 " message on the first run of the Sub. On subsequent runs it
is ok ?!
(The "str_FileName = Dir " line is highlighted on Debug)

If I adjust its position on the line (not within the code itself) I
get the message on the first Sub run again!

How can this be?





Sub L()

Dim str_FileName As String 'Name of file in AllJnls folder.
Dim str_MyPath As String 'Path to the AllJnls folder.

' Loop to get all LESS IN Files.
str_MyPath = "C:\Less\In\" ' Set the path.
str_FileName = Dir(str_MyPath) ' Retrieve the first
entry.

Do While str_FileName < "" 'Loop for each file.

'Calculate

Debug.Print str_FileName

str_FileName = Dir ' Get next file.

Loop
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Weird VBA problem

you need to specify which object the calculate method is to work on be that
the application, or a range.



I can put in "Calculate", "Range("A1:F10").Calculate" or a fully
qualified path the problem is the same.

The page being calculated is nothing special.

My original loop contained a lot more code most of which works fine.
I have have traced the problem to this calculate keyword although I
don't think this is the root of the problem as I have a call to
another sub that gives the same error.

Is anyone aware of any Excel bugs that sometimes cause a DIR to fail?

Thanks.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Weird VBA problem

Could this possibly be a corrupt Excel workbook ?
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
weird problem WarrenK Setting up and Configuration of Excel 0 June 5th 09 05:46 PM
Weird Problem Gaurav[_2_] Excel Worksheet Functions 4 December 17th 07 04:27 PM
Weird problem Sue Excel Worksheet Functions 2 November 29th 05 12:10 PM
Weird Problem Patrick Excel Worksheet Functions 4 March 28th 05 02:29 AM
weird focus problem Ron de Bruin Excel Programming 0 August 8th 03 03:54 PM


All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"