I have to open an excel file in access, but whenever I open that file, I have to choose "OK" on popup msgbox from vba excel.
how to turn off this msgbox automatically ?
I know it is imposible to close modal windows within 1 application. But in my situation, I find a way to do this with my code below.
my Code up-till now: -
Public Function OpenExcelIdle(strFullFileName As String)
-
On Error GoTo Err::
-
Dim xlapp As Object
-
Set xlapp = CreateObject("Excel.Application")
-
Dim books As Object
-
xlapp.EnableEvents = False
-
xlapp.AutomationSecurity = 3
-
xlapp.Visible = False
-
xlapp.DisplayAlerts = False
-
xlapp.screenupdating = False
-
-
xlapp.workbooks.Open (strFullFileName)
-
-
Set books = xlapp.ActiveWorkBook
-
-
books.Save
-
books.Close
-
xlapp.Quit
-
Exit_F::
-
Exit Function
-
Err::
-
xlapp.DisplayAlerts = True
-
xlapp.screenupdating = True
-
xlapp.Quit
-
Set books = Nothing
-
Set xlapp = Nothing
-
Resume Exit_F::
-
End Function
-
the code disable event trigger to disable any msgbox appear from on_open event.
set to force disable macro that no macro could run.
then even disable screenupdating or DisplayAlerts, so Excel will completely be opened in silence...
Edit: actually my code work well, but I don't know whether any other situations could happen or not, so plz help me improve it, thank ^^
Edit2: == I think we should move this question to insight section.
4 1581 zmbd 5,501
Recognized Expert Moderator Expert
Some slight tweaking to your code - removed extra colons and renamed the branch point labels. Tweaked your error handler. Added a return value for the function so that you can at least test in code if the function ran. Ideally, IMHO, in the error trap you should have some sort of user feedback. - Public Function OpenExcelIdle(strFullFileName As String)
-
On Error GoTo Errtrap
-
Dim xlapp As Object
-
Dim books As Object
-
'
-
OpenExcelIdle= True
-
'
-
Set xlapp = CreateObject("Excel.Application")
-
'
-
xlapp.EnableEvents = False
-
xlapp.Visible = False
-
'
-
xlapp.workbooks.Open (strFullFileName)
-
'
-
Set books = xlapp.ActiveWorkBook
-
'
-
books.Save
-
books.Close
-
'
-
Exit_f:
-
If not books is Nothing Then Set books = Nothing
-
If not xlapp is Nothing Then
-
xlapp.Quit
-
Set xlapp = Nothing
-
end if
-
'
-
Exit Function
-
Errtrap:
-
OpenExcelIdle= False
-
Resume Exit_F
-
End Function
Once the events are disabled in the application and the interactive interface is hidden, unless there is a security warning (and you cannot normally disable these via code, not even with the DisplayAlerts set to false); there is no need to disable screen updates, alerts, nor change the macro-security level (no events, no on_open; thus, no trigger for Macro Security)...
As for this being an Insights article, it needs a little more depth. This method, or at least similar methods, can be found in various other blogs, forums, and books so IMHO to be an ISA there needs to be a little more information about application of method and the writing style needs to be more along the lines of a professional journal entry or tutorial... maybe not as formal as a peer reviewed journal but never the less, in that general grammatical style. :)
ok, Thank zmbd, this's just a 5mins working code so it can't be beautiful... as your.
btw, I did not learn anything about code, so I don't know how it work, just trap all the case I think that can happen.
my final code really complex now, I did not use "try ... catch", the method that I have read in a couple day very usefull == I think I'll use it later when i post new code here ^^
edit: forgot to mention, to trap Error, I use breakpoint to test overtime, so I'll know what wrong by looking carefully into each variables and debug/msgbox by myself to understand what wrong.. that how I Learn vba now == and it quite usefull for me, I understand all most this vb-language.
zmbd 5,501
Recognized Expert Moderator Expert
When troubleshooting code; msgbox , debug.print , etc... are good tools to use.
I would suggest however, that one avoids setting the breakpoint (that little red dot :) ) instead using the STOP command. There are some known glitches that can creep in to one's code on the compiler side that are difficult to diagnose and remove when using the breakpoint method and making changes to the code that do not seem to happen when using the STOP command.
The watch window is also a very good tool. I use it quite frequently to verify that variables have reached certain inputs and so forth.
The locals window has also proven extremely useful as one can watch the variables and objects while stepping thru code in debug state.
I do have a little boilerplate of tutorials and resources that I will PM you latter (Monday?) my PC crashed a little while back and I'm still merging my backups from the old system to the new.... different OS versions :)
the point is, I use F8 to step-by-step look where code run into, and I trapped error. so it's clearly enuf for me ^^
different OS version, hope you don't use win 10... that OS's [it's ...]
instead improve touch screen in desktop, they moved to "modern UI" which worser than ever....
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Gary Cobden |
last post by:
Hi
I have a routine that uses VBA to open a hidden occurence of Excel,
and do background computations.
However, in the event that the routine terminates abnormally, I have
not been able to...
|
by: Jim |
last post by:
This should really be simple, but I can't figure it out. I have some
VB that exports a table in an Excel format ("C:\NewReport.xls"). After
the export is done, I simply want to have some code...
|
by: ZW |
last post by:
Hi there,
I use following code to convert a datagrid data to Excel.
However, if I use IE to access the page, it opens an empty
excel page. If I access it by Netscape, it can open it
with excel...
|
by: Daniel |
last post by:
Hi all,
Can i open and edit the excel sheet on web page after downloading?
After editing, i close the web page and the excel file auto upload to the
server.
Is it possible? I really struggling...
|
by: Rich Wallace |
last post by:
Hello all,
Looking for suggestions and tips if possible.
I have an application running on a file server that utilizes the
FileSystemWatcher to trap when any Excel files are saved by a user. I...
| |
by: Rich Wallace |
last post by:
Hi all,
I have a VB app that runs and manages individual XLS files within a single
COM object. Upon processing the final fie, I attempt to close out the EXCEL
object and release it using...
|
by: natrajsr |
last post by:
Hi,
I want to load the data of a excel sheet or in the exact excel
sheet format into a Rich TextBox control.
I have already worked with loading WORD into a Rich TextBox. It is
working fine.;...
|
by: SimeonD |
last post by:
Hi
I have an access database called Sales.Mdb
In vb.net 2005, I'd like to open it. Which I can do.
What I can't figure out is how to figure out if Sales.Mdb is open already.
If so, I want to open...
|
by: puella |
last post by:
I would really appreciate it if someone could help me!
I need to create charts based on Access queries (I use MS Office 2010.) I was hoping to use Access native charts and to insert them in the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |