VBA opens multiple files for processing.
Executable file (with VBA)
And, due to circumstances, only the A.xls file is closed during processing to free up memory.
However, for example, if there is a problem in the middle of processing, the error processing is skipped.Current situation
Even if there is a problem during the process and the error process is skipped,
The code that closes all files and frees memory at the end of processing.
However, for example, if you have trouble closing the A.xls file and skipping error processing
An error occurs in the code that closes the A.xls file and releases the memory.
'Close A.xls file (A.xls = SendFile) 'There is a closing process in the middle of the process. SendFile.Close SaveChanges: = True 'Processing when an error occurs 'Close A.xls file If SendFile.Name<>"" Then SendFile.Close SaveChanges: = True End If 'Error message MsgBox "Error in processing Capability Building ("&strError&")"&_ vbCrLf&"Error Number:"&Err.Number&_ vbCrLf&"Error description:"&Err.Description End Sub
The above part closes the A.xls file in the middle of processing.
If an error occurs after that,
'Close A.xls file If SendFile.Name<>"" Then SendFile.Close SaveChanges: = True End If
An error occurs in this part.
It seems that A.xls (= SendFile.Name) has already been closed.
In this case
① Determine if the file is open
② Close if open
, but I can't find that code.
Is there code that determines if a file is open?
Answer # 1
SendFile.Close Set SendFile = Nothing
As a matter of fact, in error processing, it can be closed if it is not Nothing.
Answer # 2
Wouldn't it be like this?
exists = False For Each wk In Workbooks If wk.Name = book name Then exists = True Exit For End If Next
Answer # 3
How about ignoring errors by writing
On Error Resume Nextbefore
- i don't know how to save an image (jpg format) from a psd file
- [vba] i don't know how to iterate
- [vba] i don't know how to log in automatically from the next time [keep login]
- i want to know how to use exit do with vba
- c ++ - i want to know how to push_back std :: vector
- utf-8 - i don't know how to install neologd
- mysql - i don't know how to access the database
- python - i don't know how to resolve the error
- i don't know how to start mysql
- c# - i don't know how to deal with the error argumentoutofrangeexception and how to use list
- ruby on rails - i want to know how to complicate rails url
- python - i don't know how to add +1 to user-specific functions and functions
- i want to know how to remove and restore
- [django] i want to know how to pass the user name to html in the class-based view
- How to save text file in python
- i don't know how to include dll etc in c#exe
- c ++ - i don't know how to use a function that uses void
- vba - dir function open a file with an arbitrary number of digits using a wildcard
- i want to save a file using the urldownloadtofile function in excel vba, but the file is broken and it does not work
- vba - create folders automatically
- vba - about createobject("shellapplication")
- vba - how to display an image url in excel as an image in excel
- i want to insert columns one by one with vba, but if there is a smart way please tell me
- excel vba sort collapses
- vba - macro to extract rows containing specific words and output to another worksheet
- vba - cannot store the total value extracted by the auto filter in a variable
- excel vba i want to draw continuous shapes