473,503 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to close the msgbox from Excel vba when open excel in Access ?

215 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function OpenExcelIdle(strFullFileName As String)
  2. On Error GoTo Err::
  3. Dim xlapp As Object
  4. Set xlapp = CreateObject("Excel.Application")
  5. Dim books As Object
  6. xlapp.EnableEvents = False
  7. xlapp.AutomationSecurity = 3
  8. xlapp.Visible = False
  9. xlapp.DisplayAlerts = False
  10. xlapp.screenupdating = False
  11.  
  12. xlapp.workbooks.Open (strFullFileName)
  13.  
  14. Set books = xlapp.ActiveWorkBook
  15.  
  16. books.Save
  17. books.Close
  18. xlapp.Quit
  19. Exit_F::
  20. Exit Function
  21. Err::
  22. xlapp.DisplayAlerts = True
  23. xlapp.screenupdating = True
  24. xlapp.Quit
  25. Set books = Nothing
  26. Set xlapp = Nothing
  27. Resume Exit_F::
  28. End Function
  29.  
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.
Nov 6 '15 #1
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.

Expand|Select|Wrap|Line Numbers
  1. Public Function OpenExcelIdle(strFullFileName As String)
  2.    On Error GoTo Errtrap
  3.    Dim xlapp As Object
  4.    Dim books As Object
  5. '
  6.    OpenExcelIdle= True
  7. '
  8.    Set xlapp = CreateObject("Excel.Application")
  9. '
  10.    xlapp.EnableEvents = False
  11.    xlapp.Visible = False
  12.    xlapp.workbooks.Open (strFullFileName)
  13. '
  14.    Set books = xlapp.ActiveWorkBook
  15.    books.Save
  16.    books.Close
  17. '
  18. Exit_f:
  19.    If not books is Nothing Then Set books = Nothing
  20.    If not xlapp is Nothing Then 
  21.       xlapp.Quit
  22.       Set xlapp = Nothing
  23.    end if
  24. '
  25. Exit Function
  26. Errtrap:
  27.    OpenExcelIdle= False
  28.    Resume Exit_F
  29. 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. :)
Nov 7 '15 #2
hvsummer
215 New Member
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.
Nov 7 '15 #3
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 :)
Nov 7 '15 #4
hvsummer
215 New Member
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....
Nov 7 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5541
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...
1
2878
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...
8
1606
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...
6
6743
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...
0
2221
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...
4
3064
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...
3
4515
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.;...
14
4608
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...
1
5688
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...
0
7064
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...
0
7261
Oralloy
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,...
1
6974
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...
0
7445
tracyyun
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...
0
4665
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...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
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 ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.