Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / September 2006

Tip: Looking for answers? Try searching our database.

Run time error executing Excel code (VBA)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
luis.a.roman@gmail.com - 28 Sep 2006 01:46 GMT
When I execute the code below on the second iteration reading the file
I get run-time error 1004.

Can someone help me correct this problem? I don't understand what I'm
missing.

Thank you - Luis

===============CODE ============================================
Option Compare Database
Public HoldRequirement As String
Public counter As Integer
Public activeCnt As Integer

Public parseproject As String

Sub ReadFileToProcess()
'Read the directory of the folder that contains the
'files to be loaded
activeCnt = 0
Dim fPathDirectory As String, fName As String
Dim fileLoaded1 As String, filesUploadedcnt As Integer
Dim tblProjectsAndRequirements As String, debugFlag As Boolean
debugFlag = True

'The Name of the table that the records are going to be stored
tblProjectsAndRequirements = "cpyProjectsAndRequirements"
filesUploadedcnt = 0
fPathDirectory = "F:\EVMSFiles\ITPlanningRequirements\"
fName = Dir(fPathDirectory, vbDirectory)    ' Retrieve the first entry
DoCmd.Hourglass True
Do While fName <> ""                        ' Start the Loop
  If fName <> "." And fName <> ".." Then
     If Left(fName, 3) = "200" Then
        If debugFlag = True Then
           Debug.Print "Path Name= " & fPathDirectory & "File Name=" &
fName
           filesUploadedcnt = filesUploadedcnt + 1
           Dim xlsApp As Excel.Application
           Dim xlswkb As Excel.Workbook
           Set xlApp = New Excel.Application
           'ActiveSheet.Cells.MergeCells = False
           With xlApp
                .Visible = True
                 Set xlWB =
.Workbooks.Open("F:\EVMSFiles\ITPlanningRequirements\" & fName, ,
False)
                 If activeCnt = 0 Then
                   activeCnt = activeCnt + 1
                   ActiveSheet.Cells.MergeCells = False
                End If
           End With
           Call FormatRequirement

           xlApp.Quit
           Set xlsApp = Nothing
           Set xlWB = Nothing
           Set xlswkb = Nothing
           Set xlsApp = Nothing
           Set xlApp = Nothing
           fileLoaded1 = fileLoaded1 & fName & " "
           DoCmd.Hourglass False
        Else
         DoCmd.Hourglass True
         DoCmd.Hourglass False
        End If
      End If
  End If
   fName = Dir
Loop
MsgBox "Files Loaded: " & filesUploadedcnt, , "JSF Projects and
Requirements"

End Sub
Sub FormatRequirement()
Range("A3").Select                    '---SECOND ITERATION ABEND - Run
time error 1004
counter = 0
HoldRequirement = Sheets(1).Range("a3").Value
Do Until counter > 550
  Call fillRequirement
Loop
' Insert column for the Project
roy.patrice@uqam.ca - 28 Sep 2006 02:48 GMT
Hi Luis,

Other could help you more but ... isn't a code 1004 when you don't
close a macro and recall it ? You may want to check that first.

Pat
http://youlearnexcel.com

> When I execute the code below on the second iteration reading the file
> I get run-time error 1004.
[quoted text clipped - 79 lines]
> Loop
> ' Insert column for the Project

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.