duncanb7
asked on
how to avoid file re-bulid message in Excel VBA
Dear Expert,
I have many files to open and close in Excel 2003 VBA, sometimes I experience
run-tim error and try to re-do the job by error resume next or goto , but
sometimes, Excel will re-bulid the file failed at error of "the open method of file failed"
so we need to pass the dialog window of "Microsoft Office Excel" to click yes
button and the code is hang up even you using error resume next.
The case is similar for avoid the security warning. Any website or suggestion for
download the add-in or com add-on for Excel 2003 VBA to avoid such warning window comes out
so I can re-start the code
Please advise
Duncan
I have many files to open and close in Excel 2003 VBA, sometimes I experience
run-tim error and try to re-do the job by error resume next or goto , but
sometimes, Excel will re-bulid the file failed at error of "the open method of file failed"
so we need to pass the dialog window of "Microsoft Office Excel" to click yes
button and the code is hang up even you using error resume next.
The case is similar for avoid the security warning. Any website or suggestion for
download the add-in or com add-on for Excel 2003 VBA to avoid such warning window comes out
so I can re-start the code
Please advise
Duncan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Opening 50 workbooks could consume a large amount of memory. And they're not Excel files, they're browser files (.htm). Can you give us a little more scope on what it is you are trying to do? You are referring to this as a test. A test for what? Details, give us lots of details. Without it we won't know the true scope of this and will have a much more difficult time in helping you with a solution.
Zack
Zack
ASKER
it is product files, daily I work for it around and save it and sent it to
my domian site so I pick to use htm format. The opentest()
is for debugging in small code but similar error happen in my
original code that is huge vba code.
my domian site so I pick to use htm format. The opentest()
is for debugging in small code but similar error happen in my
original code that is huge vba code.
ASKER
I try to use dim obj as workbook and set obj-workbooks.open()
and set obj=nothing that doesn't help at all
Yes, it is many file opening but it is runing one by one, one open and close and next.
So memory should be no problem at all, I use'Debug.Print "Microsoft Excel is currently using " & _
Application.MemoryUsed & " bytes" to check Excel memory usage that is only 160k byte
Sub opentest()
Dim k As Integer
dim obj as workbook
k = 0
Do Until k = 50
On Error Resume Next
set obj=Workbooks.Open (filename:="D:\myexcel\" & K & ".htm", ReadOnly:=False)
If Err.Number <> 0 Then
Debug.Print Err.Description
Err.Clear
Exit Sub
End If
Err.Clear
ActiveWorkbook.Activate
'''''''''''''do some calcution here
ActiveWorkbook.Save
ActiveWorkbook.Close False
k = k + 1
set obj=nothing
Loop
End Sub
and set obj=nothing that doesn't help at all
Yes, it is many file opening but it is runing one by one, one open and close and next.
So memory should be no problem at all, I use'Debug.Print "Microsoft Excel is currently using " & _
Application.MemoryUsed & " bytes" to check Excel memory usage that is only 160k byte
Sub opentest()
Dim k As Integer
dim obj as workbook
k = 0
Do Until k = 50
On Error Resume Next
set obj=Workbooks.Open (filename:="D:\myexcel\" & K & ".htm", ReadOnly:=False)
If Err.Number <> 0 Then
Debug.Print Err.Description
Err.Clear
Exit Sub
End If
Err.Clear
ActiveWorkbook.Activate
'''''''''''''do some calcution here
ActiveWorkbook.Save
ActiveWorkbook.Close False
k = k + 1
set obj=nothing
Loop
End Sub
Memory doesn't quite work like that. While running a sub routine, even opening and closing workbooks can take up memory. It shouldn't be a whole lot of process memory though, but we're really only worried about the memory the VBA is using.
Can you post the code you're actually having problems with? I don't want to post code to help you in your test, then find out you need more for your "actual" project. It makes it twice as much work for us.
Zack
Can you post the code you're actually having problems with? I don't want to post code to help you in your test, then find out you need more for your "actual" project. It makes it twice as much work for us.
Zack
SECURITY WARNING:
Click TOOLS - MACRO - SECURITY - SELECT LOW.
Scott C
Click TOOLS - MACRO - SECURITY - SELECT LOW.
Scott C
? If the OP us running a macro, why would they need to lower their security settings from Medium to Low? Asumming it's at Medium. Don't really see the logic here, Scott. Can you fill me in?
Zack
Zack
ASKER
Click TOOLS - MACRO - SECURITY - SELECT LOW. that is
same as before, doesn't help at all
After I check, if the file size is small that is better,the open file lopp is passed
my each file is around 200K in which it
has chart object
same as before, doesn't help at all
After I check, if the file size is small that is better,the open file lopp is passed
my each file is around 200K in which it
has chart object
Can we see your full code? Again, we can't do much without that, except give you a patch for your test code, which probably won't help you much in the end.
Zack
Zack
ASKER
Finally is solved and I don't know
why the problem is gone today
suddenly
why the problem is gone today
suddenly
ASKER
The problem is sometimes, the marco is passed but sometimes are not.
it is randomly to have open method of fail object file error at 1.htm"
sometimes, error is happen at openfile at 10.htm , sometimes at 29 htm,
When it fail, microsoft office excel title window will comes and ask you
whether need to report it ot MS , select yes to report and no for not report.
And then it will rebuild the fail file and quit my VBA program.
So feel it is annoying, after I check whether it is re-building the error file that
is no much different. I mean actually the error file is no problem at all for my application
My code is attach,I would like to avoid those MS warning or ask yes or no button dialog box
application.displayalert= false is not wokring, any suggestion ?
Sub opentest()
Dim k As Integer
k = 0
Do Until k = 50
On Error Resume Next
Application.Workbooks.Open
'SourceWorkbook.Activate
If Err.Number <> 0 Then
Debug.Print Err.Description
Err.Clear
Exit Sub
End If
Err.Clear
'Do Until ActiveWorkbook.Name = k & ".htm"
'Loop
'ActiveWorkbook.Activate
'
ActiveWorkbook.Activate
ActiveWorkbook.Save
ActiveWorkbook.Close False
k = k + 1
Loop
End Sub